<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>样式绑定</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
.activated {
color: red;
}
</style>
</head>
<body>
<div id="app">
<div
:class="[activated,activatedOne]"
@click="handleClick"
>{{ msg }}</div>
</div>
<script>
let vm = new Vue({
el: '#app',
data: {
msg: 'hello world',
activated: '',
activatedOne:'activated-one'
},
methods: {
handleClick: function () {
this.activated = this.activated==='activated'?'':'activated'
}
}
})
</script>
</body>
</html>
Vue之样式绑定(二)
最新推荐文章于 2024-07-18 07:29:27 发布