title | date | categories | tags | |||
---|---|---|---|---|---|---|
学习vue.js的记录 |
2017-06-19 02:09:40 -0700 |
前端 |
|
<Excerpt in index | 首页摘要> vue.js开发文档:https://cn.vuejs.org/v2/guide/
<The rest of contents | 余下全文>
<!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">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<title>Document</title>
</head>
<body>
<div id="app">
{{message}}
</div>
</body>
<script>
var app=new Vue({
el:'#app',
data:{
message:"你好",
},
});
</script>
</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">
<script src="vue.js"></script>
<title>Document</title>
</head>
<body>
<div id="div1">
<span v-bind:title="message">鼠标停留几秒试试</span>
</div>
</body>
<script>
var div1=new Vue({
el:"#div1",
data:{
message:"这个页面加载于"+new Date(),
},
});
</script>
</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">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<title>Document</title>
</head>
<body>
<div id="app">
<p v-if="seen">哈哈哈哈</p>
</div>
</body>
<script>
var app=new Vue({
el:"#app",
data:{
seen:false,
//在控制台写入app.seen=true试试
},
});
</script>
</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>Document</title>
<script src="vue.js"></script>
</head>
<body>
<div id="app">
<ol>
<li v-for="todo in todos">
{{todo.text}}
</li>
</ol>
</div>
</body>
<script>
//在控制台输入app.todos.push({"text":"你大爷"})
var app=new Vue({
el:"#app",
data:{
todos:[
{"text":"哈哈哈哈哈哈哈"},
{"text":"ni hao ma "},
{"text":"嘎嘎嘎嘎"},
],
},
});
</script>
</html>
为了让用户和你的应用进行互动,我们可以用 v-on 指令绑定一个事件监听器,通过它调用我们 Vue 实例中定义的方法:
<!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>Document</title>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
</head>
<body>
<div id="app">
<p>{{message}}</p>
<button v-on:click="reverseMessage">点击我试试</button>
</div>
</body>
<script>
var app=new Vue({
el:"#app",
data:{
message:"你好",
},
methods:{
reverseMessage:function(){
this.message=this.message.split("").reverse().join('');
//这里的this应该是app
},
},
});
</script>
</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">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<title>Document</title>
</head>
<body>
<div id="app">
<p>{{message}}</p>
<input type="password" v-model="message">
</div>
</body>
<script>
var app=new Vue({
el:"#app",
data:{
message:"哈哈哈哈",
},
});
</script>
</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">
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<title>Document</title>
</head>
<body>
<div id="app">
<ol>
<todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item>
</ol>
</div>
<script>
Vue.component('todo-item',{
props:['todo'],
template:'<li>{{todo.text}}</li>'
});
var app=new Vue({
el:"#app",
data:{
groceryList:[
{text:"胡萝卜"},
{text:"白菜"},
{text:"土豆"},
{text:"随便其他的蔬菜"}
]
},
});
</script>
</body>
</html>