3.vue屬性的繫結
1.在vue中編寫的內容:
//在使用vue之前必須例項化vue物件
new Vue({
/*el:指element 需要獲取的元素,一定是html中根容器元素
以後所有的操作均是在這個根容器中進行操作
*/
el:"#vue-app",
/*
data:用於資料的儲存,用來寫屬性
以key-value的值進行儲存
*/
data:{
name:"zx",
website:"https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png",
webTag: <a href=' https://www.google.com/images/branding/googlelogo/2x/googlelogo_light_color_272x92dp.png'>谷歌</a>,
},
/**
* 使用method來儲存方法,
* 使用greet來進行呼叫
* 使用this獲取當前容器的內容
* this.name:就是指先找到當前容器的data然後在找到name對應的屬性
*/
methods: {
greet:function(name){
return 'Hello Word' + name + " " + this.name;
},
}
})
2.在html檔案中編寫:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>index.html</title>
<!-- 用於線上引用vue.js -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<!-- 引用css檔案 -->
<link rel="stylesheet" href="../css/style.css">
</head>
<body>
<!--vue-app就是我們的根容器,vue均是對vue操作-->
<div id="vue-app">
<!--v-bind:用於繫結屬性-->
<a v-bind:href="website">百度</a>
<input type="text" v-bind:value="name">
<!--v-html:用於插入標籤-->
<p v-html:"webTag"></p>
</div>
<script src="../js/app.js"></script>
</body>
</html>