<template> <!-- 支持 --> <view class="container" :class="computedClassStr"></view> <view class="container" :class="{active: isActive}"></view> <!-- 不支持 --> <view class="container" :class="computedClassObject"></view> </template> <script> export default { data () { return { isActive: true } }, computed: { computedClassStr () { return this.isActive ? ‘active‘ : ‘‘ }, computedClassObject () { return { active: this.isActive } } } } </script>
vue用 computed 方法生成 class 或者 style 字符串,插入到页面中
原文:https://www.cnblogs.com/cocoaguo/p/14228603.html