html code
<p id="box"> <strong>阿斯顿发</strong> </p>
css code
.red { color: red; } .gray { background-color: gray; }
js code
window.onload = function() { new Vue({ el: '#box', data: { red: 'red', gray: 'gray' } }); }
How to write the style to take effect
:class="[red, gray]" The data attribute in the vue parameter is called
<strong :class="[red, gray]"></strong>
:class="{red : true, gray: true}"
<strong :class="{red: true, gray: true}"></strong>
The second method can also call the data attribute of the vue parameter. Remember, everything in Vue is data
new Vue({ el: '#box', data: { red: 'red', gray: 'gray', a: true, b: false } });
<strong :class="{red: a, gray: b}"></strong>
:class="json", a simplified version of the second method, the official version
new Vue({ el: '#box', data: { red: 'red', gray: 'gray', json: { a: true, b: false } } });
<strong :class="json"></strong>
is basically the same as class
:style="{}"
<strong :style="{color: 'red', backgroundColor: 'gray'}"></strong>
:style="a"
new Vue({ el: '#box', data: { red: 'red', gray: 'gray', a: { color: 'red', backgroundColor: 'gray' //注意复合样式的书写规范 } } });
<strong :style="a">阿斯顿发</strong>
:style="[a, b]", a, b correspond to the two json data in data
More class and style in vue For relevant setting methods and related articles, please pay attention to the PHP Chinese website!