第一个VUE实例
<!DOCTYPE html>
<html>
<head>
<title>第一个Vue程序</title>
<script type="text/javascript" src="vue.js" charset="utf-8"></script>
</head>
<body>
<div id="app">
{{ message }}
</div>
<script type="text/javascript">
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
</script>
</body>
</html>
Vue数据与方法
<!DOCTYPE html>
<html>
<head>
<title>Vue数据与方法</title>
<script type="text/javascript" src="vue.js" charset="utf-8"></script>
</head>
</head>
<body>
<div id="app">
{{a}}
</div>
<script type="text/javascript">
var data = { a: 1 }
var vm = new Vue({
el:"#app",
data: data
})
vm.$watch('a', function (newValue, oldValue) {
console.log(newValue,oldValue);
})
vm.$data.a="new vue";
</script>
</body>
</html>
Vue生命周期
<!DOCTYPE html>
<html>
<head>
<title>Vue生命周期</title>
<script type="text/javascript" src="vue.js" charset="utf-8"></script>
</head>
<body>
<div id="app">
{{msg}}
</div>
<script type="text/javascript">
var vm=new Vue({
el:"#app",
data:{
msg:"hi vue",
},
beforeCreate:function(){
console.log('bdforeCreate');
},
created:function(){
console.log("created");
},
beforeMount:function(){
console.log("beforeMount");
},
mounted:function(){
console.log("mouted");
},
beforeUpdate:function(){
console.log("beforeUpdate");
},
updated:function(){
console.log("updated");
}
});
setTimeout(function(){
vm.msg="change....";
},3000);
</script>
</body>
</html>
Vue模板语法-插值
<!DOCTYPE html>
<html>
<head>
<title>Vue模板语法-插值</title>
<script type="text/javascript" src="vue.js" charset="utf-8"></script>
</head>
<body>
<div id="app">
{{msg}}
<p>Using mustaches: {{ rawHtml }}</p>
<p>Using v-html directive: <span v-html="rawHtml"></span></p>
<div v-bind:class="dynamicId">test...</div>
{{ number + 1 }}
{{ ok ? 'YES' : 'NO' }}
{{ message.split('').reverse().join('') }}
</div>
<script type="text/javascript">
var vm =new Vue({
el:"#app",
data:{
msg:"hi vue",
rawHtml:'<span style="color:red">this is should be red</span>',
dynamicId:'color',
number:10,
ok:true,
message:'v u e'
}
});
vm.msg="hi....";
</script>
<style type="text/css">
.color{
color: red;
font-size:24px;
}
</style>
</body>
</html>
Vue 模板语法-指令
<!DOCTYPE html>
<html>
<head>
<title>Vue 模板语法-指令</title>
<script type="text/javascript" src="vue.js" charset="utf-8"></script>
</head>
<body>
<div id="app">
<p v-if="seen">现在你看见我了</p>
<a v-bind:href="url">百度</a>
<div @click="click1">
<div @click.stop="click2">
click me
</div>
</div>
</div>
<script type="text/javascript">
var vm=new Vue({
el:"#app",
data:{
seen:true,
url:'www.baidu.com'
},
methods:{
click1:function(){
console.log("click1....");
},
click2:function(){
console.log("click2....");
}
}
})
</script>
</body>
</html>