vue.js 动态设置样式
控制多个样式:<!DOCTYPE html><html><head><meta charset="utf-8"><title>Vue 测试实例</title><script src="ht
·
控制多个样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试实例</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<style>
.text-danger {
width: 100px;
height: 100px;
background: red;
}
.active {
width: 100px;
height: 100px;
color: green;
}
</style>
</head>
<body>
<div id="app">
<div v-bind:class="[isTest ? errorClass : '',isActive ? activeClass : '']">ceshi</div>
</div>
<script>
new Vue({
el: '#app',
data: {
isActive: true,
isTest:true,
activeClass: 'active',
errorClass: 'text-danger'
}
})
</script>
</body>
</html>
控制单个样式:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Vue 测试</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<style>
.active {
width: 100px;
height: 100px;
background: green;
}
.text-danger {
background: red;
}
</style>
</head>
<body>
<div id="app">
<div class="static"
v-bind:class="isActive?'active':''">
</div>
</div>
<script>
new Vue({
el: '#app',
data: {
isActive: true,
hasError: true
}
})
</script>
</body>
</html>
更多推荐
已为社区贡献2条内容
所有评论(0)