<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
</style>
</head>
<body>
<script src="../js/vue.js"></script>
<!-- 绑定class方法一 -->
<!-- <div :class="{ active: isActive }" id="example"></div> -->
<div class="static"
:class="{ active: isActive, 'text-danger': hasError }" id="example">
<!-- 绑定style的方式一(常用) -->
<div v-bind:style="styleObject">方式一</div>
<!-- 绑定style的方式二 -->
<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }">方式二</div>
</div>
<script>
var vm = new Vue({
el: '#example',
data: {
isActive: true,
hasError: true,
styleObject: {
color: 'red',
fontSize: '13px'
}
}
// data: {
// activeColor: 'red',
// fontSize: 30
// }
})
</script>
</body>
</html>
动态绑定style设置样式的方法
最新推荐文章于 2024-05-27 09:10:02 发布