Vue中操作CSS的样式绑定,以及父子组件样式传递
可以看到样式已经绑定到DOM节点上了
注:标签属性绑定使用v-bind/:
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>lesson 9title>
<style>
.red {
color: red;
}
.green {
color: green;
}
style>
<script src="https://unpkg.com/vue@next">script>
head>
<body>
<div id="root">div>
body>
<script>
const app = Vue.createApp({
data() {
return {
classString: 'red',
classObject: { red: false, green: true },
classArray: ['red', 'green', {brown: false}],
styleString: 'color: yellow;background: orange',
styleObject: {
color: 'orange',
background: 'yellow'
}
}
},
template: `
Hello World
`
});
app.component('demo', {
template: `
one
two
`
})
const vm = app.mount('#root');
script>
html>