vue使用笔记二

es6\es2015特性
http://lib.csdn.net/article/reactnative/58021?knId=1405

使用express-generator初始化你的项目目录
https://www.cnblogs.com/zjhr/p/5227042.html

1.Vue 基本属性与生命周期
https://www.jianshu.com/p/0ae4b5b8b012

var vm = new Vue({
name:'root',
el:"#app",
// 数据
data: { a: 1 } / Function, // data类型根实例为Object,组件中为Function
props:[]/{}, // 设置父组件传递给子组件的数据限制
computed:{}, // 计算属性
watch:{}, // 监控属性
methods:{}, // 事件操作
// 资源
directives:{}, // 内部指令
filters:{}, // 内部过滤器
components:{}, // 内部组件
// 生命周期:实例创建 => 编译挂载 => 组件更新 => 销毁
beforeCreate(){
console.log('beforeCreate ==> 实例创建')
},
created(){
// 可以操作data, 但未生成DOM(未挂载)发起异步请求,初始化组件状态数据 data
console.log('created ==> 实例创建完成,属性已绑定')
},
beforeMount(){
console.log('beforeMount ==> 模板编译/挂载之前')
},
mounted(){
// 已生成DOM到document中,可访问this.$el属性
console.log('mounted ==> 模板编译/挂载之后')
},
beforeUpdate(){
console.log('beforeUpdate ==> 组件更新之前')
},
updated(){
// 操作DOM $('#box1')
console.log('updated ==> 组件更新之后')
},
activated(){
// 操作DOM $('#box1')
console.log('activated ==> 组件被激活时(for keep-alive组件)')
},
deactivated(){
console.log('deactivated ==> 组件被移除时(for keep-alive组件)')
},
beforeDestroy(){
// 解除事件绑定,销毁非Vue组件实例等 如:this.$off('event1') select2.destory()
console.log('beforeDestroy ==> 组件销毁之前')
},
destroyed(){
console.log('destroyed ==> 组件销毁之后')
}
})

2.vue中 data与props区别
https://blog.csdn.net/xukongjing1/article/details/82457585

子组件中的data数据,不是通过父组件传递的是子组件私有的,是可读可写的。
子组件中的所有 props中的数据,都是通过父组件传递给子组件的,是只读的。


3.Vue中 如何才能不使用{{msg}} 来显示信息

4.vue 中 组件必须写<component></component> 要有开始和结尾

5.vue 中data 要使用return 返回一个对像

6.props中 使用的是属性值对应的是个json对像 如:属性值:{默认值,类型}

V-bind:text 或者{{}}

7.组件名称建议定义成两个单词,防止有些标签与h5标签重复,如 content组件是h5自有标签

8.vue使用路由
import Router from 'vue-router'

9.路由分到多个文件管理
https://blog.csdn.net/FungLeo/article/details/81014184
路由监测
https://blog.csdn.net/qq_25186543/article/details/80008671

10.vuex使用
mapState与mapGetter区别
https://segmentfault.com/q/1010000015849766

通常是在store中 另外写getter来获取state中的某个值,而后在vue组件中利用mapGetter来给组件赋值

在vuex里的action中改变路由是不太合理的。因为vuex只是状态管理。
但是真的可以在action里改变路由 可以把路由当作参数传递到action里去

 


action里的context 包括以下属性

 

mutation的第一个参数必然是state
计算属性映射到store里的getter对像中

:是自定义属性赋值
只单向是v-html 和v-text
v-model是双向绑定只能用于input

 

posted @ 2019-03-12 13:18  liuxm-刘小明  阅读(114)  评论(0编辑  收藏  举报