1、对象写法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>绑定css样式</title>
<!--引入vue-->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<style>
.basic{
width: 400px;
height: 100px;
border:1px solid black;
}
.normal{
}
.happy{
}
.sad{
}
.atguigu1{
}
.atguigu2{
}
.atguigu3{
border-radius: 20px;
}
</style>
</head>
<body>
<div id="root">
<!--对象写法-->
<div class="basic" :style="styleobj" >{{names}}</div>
</div>
<script type="text/javascript">
Vue.config.productionTip=false;
new Vue({
el:"#root",
data() {
return {
names:'test',
styleobj:{
fontSize: '40px',
color: 'red',
backgroundColor:'orange',
}
}
},
})
</script>
</body>
</html>
2、数组写法
3、总结