<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">
<h2>{{message}}</h2>
<img src="{{imagURL}}" >
<img :src="imagURL" >
</div>
<script src="../vue.js"></script>
<script>
// {{}}mustache语法只能在标签内部使用。 不用用在标签的属性绑定。
const app = new Vue({
el: ‘#app‘,
data: {
message: ‘hello‘,
imagURL: ‘http://www.zhoushan.host/static/stark/imgs/abc.png‘
}
})
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.active{
color: red;
}
.font{
font-size: small;
}
</style>
</head>
<body>
<div id="app">
<h2 :class="{active:isActive,font:isFont}">{{message}}</h2>
</div>
<script src="../vue.js"></script>
<script>
const app = new Vue({
el: ‘#app‘,
data: {
message: ‘你好,hello‘,
isActive: true,
isFont: true
}
})
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.active{
color: red;
}
</style>
</head>
<body>
<div id="app">
{{message}}
<ul>
<li v-for="(item,index) in movies" @click="addButton(index)" :class="{active: position === index}">{{item}}</li>
</ul>
</div>
<script src="../vue.js"></script>
<script>
const app = new Vue({
el: ‘#app‘,
data: {
message: ‘hello‘,
movies: [‘我是谁‘,‘天地英雄‘,‘肖生克的救赎‘],
position: ‘‘,
},
methods: {
addButton(i) {
console.log(‘点击了‘,i)
this.position = i
}
},
})
</script>
</body>
</html>
原文:https://www.cnblogs.com/ch2020/p/14815191.html