1.绑定属性
代码语言:javascript
复制<template>
<div id="app">
<!-- 绑定属性 -->
<br>
<div v-bind:title='title'>鼠标悬浮出现</div>
<br>
<img :src="url" alt="仙女">
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
title:'鼠标悬浮出现',
url:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1569319252742&di=0eaf19ed1e01d10d7f612da9434599a6&imgtype=0&src=http://img3.duitang.com/uploads/item/201603/28/20160328121906_ErzAB.thumb.700_0.jpeg'
}
}
}
</script>
<style>
</style>
2.绑定html
代码语言:javascript
复制<template>
<div id="app">
<!-- html绑定 -->
<div v-html="h"></div>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
h:'<h2>二级标题</h>'
}
}
}
</script>
<style>
</style>
3.绑定class
代码语言:javascript
复制<template>
<div id="app">
<!-- 绑定class -->
<div :class="{'red':flag,'blue':!flag}">绑定class</div>
<div :class="{'red':!flag,'blue':flag}">绑定class</div>
<ul>
<li v-for="(item,index) in list" :key=index :class="{'red':index==1,'blue':index==2}">{{item}}</li>
</ul>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
flag:true,
list:['第一行','第二行','第三行']
}
}
}
</script>
<style>
.red{color: red}
.blue{color:blue}
</style>
4.绑定style
代码语言:javascript
复制<template>
<div id="app">
<!-- 绑定style -->
<div class="box" :style="{width:boxWidth 'px'}">这是一个div</div>
</div>
</template>
<script>
export default {
name: 'app',
data () {
return {
boxWidth:300
}
}
}
</script>
<style>
.box{
height: 100px;
width: 100px;
background-color: aquamarine;
}
</style>