附有同一文件夹下的html文件和js文件
注释说的很详细
index.html的代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vue</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<!--vue-app是根容器
{{greet("afternoon")}} 是为了绑定app.js中的greet()方法,里面是传进的参数
{{name} }是直接绑定数据
v-bind:href="website" 是为了绑定app.js中设置的超链接
v-html="websiteTag" 是为了绑定标签
-->
<div id="vue-app">
<h1>{{greet("afternoon")}}</h1>
<p>name : {{name}}</p>
<p>job : {{job}}</p>
<a v-bind:href="website">web开发</a>
<input type="text" v-bind:value="job">
<p v-html="websiteTag"></p>
</div>
<script src="app.js"></script>
</body>
</html>
app.js文件代码
//实例化VUE对象
new Vue({
el:"#vue-app",
//仅限于在vue-app容器下
data:{
name:"wu",
job:"web开发",
website:"http://www.thenewstep.com",
websiteTag:"<a href='http://www.thenewstep.com'>Thenewstep</a>"
},
methods:{
greet:function(time){
return "Good " + time + " "+ this.name + " !" ;
}
}
});
/*
* el:element 需要获取的元素,一定是HTML中的根容器元素
* data用于数据的存储
* methods: 用于存储各种方法
* data-bind: 给属性绑定对应的值
*/