操作行内样式-对象语法
<!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>
</head>
<body>
<div id="app">
<h1 v-bind:style="{color: 'pink', fontSize: '18px'}">{{name}}</h1>
<h1 v-bind:style="style1">{{name}}</h1>
<h1 v-bind:style="isTrue ? style1 : style2">{{name}}</h1>
</div>
<script src="./vue.js"></script>
<script>
new Vue({
data: {
name: '赵胤祯',
isTrue: true,
style1: {
color: 'red',
fontSize: '18px'
},
style2: {
color: 'green',
fontSize: '18px'
}
}
}).$mount('#app')
</script>
</body>
</html>
操作行内样式-数组语法
<!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>
</head>
<body>
<div id="app">
<h1 v-bind:style="[{color: 'white', fontSize: '18px'}, {backgroundColor: 'green'}]">{{name}}</h1>
<h1 v-bind:style="[style1, style2]">{{name}}</h1>
<h1 v-bind:style="[isTrue ? style1 : style2]">{{name}}</h1>
</div>
<script src="./vue.js"></script>
<script>
new Vue({
data: {
name: '赵胤祯',
isTrue: true,
style1: {
color: 'red',
fontSize: '18px'
},
style2: {
color: 'green',
fontSize: '18px'
}
}
}).$mount('#app')
</script>
</body>
</html>