Vue的初始化、数据与方法
- vue.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Vue Studying</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</head>
<body>
<div id="Vue-app">
<h1>{{greet('night')}}</h1>
<h2>{{name}}</h2>
</div>
<script src="app.js"></script>
</body>
</html>
- vue.js
new Vue ({
el: '#Vue-app',
data: {
name: 'shuan',
job: 'teacher',
website: 'http://www.baidu.com',
websiteTag: '<a href:"http://www.baidu.com">百度一下,你就知</a>'
},
methods:{
greet: function (time) {
return 'Good ' + time + ' ' + this.name ;
}
}
});
笔记:
第一次尝试时, 我常常犯错的地方有:
- 初始化对象Vue后,在**el:后常常忘记#**号。
- 忘记了对官网上的vue.js库的引入。
- 忘记了对现有,本地的vue.js文件的导入。
- 在本机对象中的数据或方法有时出现不了,可能是字母写的不对应。