1.使用此方法前检查prop必定必需要写在上面,写在input上或者其余任何地方都不行(el-form-item prop属性绑定)vue
<el-form-item label='' prop="prop"> <el-input type="number" v-model.number="amt" placeholder=""></el-input> </el-form-item>
数字类型的验证须要在v-model 处加上 .number 的修饰符,这是vue自身提供的用于将绑定值转化为number类型的修饰符vuex
2.el-form riles model 属性绑定,ref 标识element-ui
this.$refs[formName].validate((valid) =>{ if(valid){ dosomething } else{ return false } })
actions 异步修改状态数组
actions 和 mutations 是相似的,不一样在于:缓存
Action提交的是Mutation,不能直接修改state中的状态,而Mutations是能够直接修改state中的状态的;异步
Action是支持异步操做的,而 MUtations 只能是同步操做函数
dispatch 和 commit的用法和区别ui
dispatch 异步操做,例如向后台请求数据 this.$store.dispatch('action方法名',值)
commit 同步操做 this.$store.commit('mutations方法名',值)this
使用 vuex 的 getterspa
有时候须要从 store 中的 state 中派生出一些装态,例如对列表进行过滤并计数, 能够使用 Vuex 的 getter (能够认为是 store 的计算属性)
getter的返回值会根据它的依赖被缓存起来,只有当她的依赖值发生了改变才会被从新计算属性
const store = new Vuex.Store({ state: { todos: [ { id: 1, text: '...', done: true }, { id: 2, text: '...', done: false } ] }, getters: { doneTodos: state => { return state.todos.filter(todo => todo.done) } } }) 经过让 getter 返回一个函数,来实现给 getter 传参 getters:{ getTodoById: (state) => (id) =>{ return state.todos.find(todo => todo.id === id) } } store.getters.getTodoById(2)
mapGetters 辅助函数: 将 store 中的 getter 映射到局部计算属性
mapGetter({ // 把 `this.doneCOunt` 映射为 `this.$store.getters.doneTodosCOunt` doneCOunt: 'doneTodosCount' })
路由中 $route.matched 数组 包含当前匹配的路径中所包含的全部片断所对应的配置参数对象