Vue.js 学习总结
2017-08-29 18:11
381 查看
Vue学习记录
数据绑定
v-model:数据双向绑定
v-text:数据展示
v-html:数据含有html将会解析
v-bind:绑定数据属性
注:v-bind 非常常用,Vue缩写 :xxx
v-on:绑定事件
注:v-on 绑定的事件,可以在Vue内置方法methods中进行逻辑处理 缩写:@xxxx
逻辑控制
v-if:接受一个boolean值来控制是否显示
v-show:与v-if类似
v-if vs v-show : 区别就是v-show通过display属性来控制是否显示,v-if 通过boolean值来控制显示
v-for: 循环条件
内置属性方法
data:数据绑定的数据都要在data里面声明
methods:v-on绑定的方法可以在这里面进行逻辑控制
compute:能够把data声明的属性进行计算
Vue组件
声明一个组件Vue.component('my-component',{template:'<p></p>'})
在html里面声明这个组件即可
<div id='app'> <my-component></my-component> </div>
在此模板中引入即可
子组件与父组件之间的通信
子组件向父组件通信(自定义事件)
通过$emit来向上传递事件<my-component @send-to-parent='hello(param)'></my-component>
父组件:
methods:{ hello:function(param){ //todo } }
子组件:
somemethod:function(){ this.$emit('send-to-parent',param) }
父组件向子组件传递事件
通过props属性来接收这个参数<my-component send-to-child='hello my son'></my-component>
子组件:
props:[ 'send-to-child' //这里指定之后就可以使用了 ]
路由(vue-router)
<div id='app'> //挂载在app下的组件,符合路由规则,则显示在router-view中 <router-view></router-view> </div>
路由配置:
//1.书写两个组件 const Foo = { template: '<div>foo</div>' } const Bar = { template: '<div>bar</div>' } //2. 路由表 const routes = [ { path: '/foo', component: Foo }, { path: '/bar', component: Bar } ] //3. 创建路由 const router = new VueRouter({ routes // (缩写)相当于 routes: routes }) //4. 挂在使用路由 const app = new Vue({ router }).$mount('#app')
动态路由
使用占位符来匹配路由表const routes = [ //这里匹配 /foo/1 { path: '/foo/:id', component: Foo } ]
注:其中参数保存在this.$router.params.id
路由嵌套
上面路由配置例子://1.书写两个组件 const Foo = { template: ' //这里又嵌套了一个<router-view> <div id='foo'> <router-view></router-view> </div> ' } const Bar = { template: '<div>bar</div>' } //2. 路由表 const routes = [ //这里新增一个children 子组件将显示在foo下的<router-view>中 //地址匹配/foo/yourpath { path: '/foo', component: Foo,children:[ path:/yourpath, component:yourcomponent] }, { path: '/bar', component: Bar } ] //3. 创建路由 const router = new VueRouter({ routes // (缩写)相当于 routes: routes }) //4. 挂在使用路由 const app = new Vue({ router }).$mount('#app')
以上就是我学习Vue总结出来的常用方法函数指令
一个比较好的学习vue的例子 基于Vue的一个后台管理模板
vue官方文档 Vue官方文档
Element UI 饿了么组件库
Vue Meterial Vue Material风格组件
相关文章推荐
- Vue.js学习总结思维导图(一)
- Vue.js基本规则提炼总结及计算属性学习
- vue.js学习总结
- Vue.js 学习要点总结(一)
- Vue.js 学习要点总结(二)
- vue.js总结学习
- 前端学习总结(二十一)Vue.js——博采众长的后起之秀
- vue.js学习笔记(三)--父子组件通信总结
- Vue.js总结学习(指令、计算属性、数据绑定)
- 【转】html5学习--JS创建和存储 cookie一些方法总结
- Vue.js学习---方法watch
- vue.js的学习1.6
- 如何学习vue.js
- Vue.js 学习10 Element基于Vue2.0的组件库
- javaScript菜鸟:学习js继承后的总结(参考大师示例)
- Vue.js第一天学习笔记(数据的双向绑定、常用指令)
- JavaScript学习总结【5】JS DOM
- Vue.js学习系列(二十六)-- 循环语句(二)
- Vue.js组件学习
- Vue.js入门学习--事件处理(五)