美文网首页
快速学习Vue要多久?

快速学习Vue要多久?

作者: MinXie | 来源:发表于2019-10-19 01:01 被阅读0次

什么是Vue?

据官方的介绍,Vue是一套构建用户界面的渐进式框架,我们不需要关注太多字面上的定义,先从最基本的语法学起

创建Vue实例,并渲染模板内容

<div id="app">
{{ message }}
</div>

var app = new Vue({
el: '#app',
data:{
message: '您好,Vue'
}
})

绑定阶段属性

<div id="app-2">
<span v-bind:title="message">
鼠标悬停几秒钟查看此处动态绑定的提示信息!
</span>
</div>

var app = new Vue({
el: '#app2',
data:{
message: '可看到tittle:您好,Vue'
}
})

节点判断

<div id="app-3">
<p v-if="seen">现在你看到我了</p>
</div>

var app = new Vue({
el: '#app3',
data:{
seen:true
}
})

列表渲染

<div id="app-4">
<ol>
<li v-for="todo in todos">
{{ todo.text }}
</li>
</ol>
</div>

var app4 = new Vue({
el: '#app-4',
data: {
todos: [
{ text: '学习 JavaScript' },
{ text: '学习 Vue' },
{ text: '整个牛项目' }
]
}
})

绑定监听事件

<div id="app-5">
<p>{{ message }}</p>
<button v-on:click="reverseMessage">反转消息</button>
</div>

var app5 = new Vue({
el: '#app-5',
data: {
message: 'Hello Vue.js!'
},
//定义事件
methods: {
reverseMessage: function () {
this.message = this.message.split('').reverse().join('')
}
}
})

数据双向绑定

<div id="app-6">
<p>{{ message }}</p>
//此处message变化会反映到data中
<input v-model="message">
</div>

var app6 = new Vue({
el: '#app-6',
data: {
message: 'Hello Vue!'
}
})

相关文章

网友评论

      本文标题:快速学习Vue要多久?

      本文链接:https://www.haomeiwen.com/subject/jvcgmctx.html