vue笔记之内联样式

如果属性带有-时,需要加单引号,如:‘font-weight’

<h1 :style="{color:'red','font-weight':200}">这是h1</h1>
<h1 :style="styleObj">这是h1</h1>
<script>
export default {
	data: function () {
		return {
			styleObj:{color:'red','font-weight':200}
		}
	}
  }
  </script>

数组形式

<h1 :style="[styleObj1,styleObj2]">这是h1</h1>
<script>
export default {
	data: function () {
		return {
			styleObj1:{color:'red','font-weight':200},
                        styleObj2:{'font-size':'30px'}
		}
	}
  }
    </script>

猜你喜欢

转载自blog.csdn.net/qq_36781179/article/details/82773236
今日推荐