Coder Social home page Coder Social logo

vue-note's People

Watchers

 avatar  avatar

vue-note's Issues

vuex

vuex
// initial state
const state = {
value: '',
}

// getters
const getters = {
history: state => state.value,
}

// actions
const actions = {}

// mutations
const mutations = {
history (state, data) {
state.value = data
},
}

export default {
state,
getters,
actions,
mutations
}

页面调用 编辑
store.commit('history', {value:0})
调用
store.getters.history.value

es6 promise

async fuc(){

let [res] =await Promise.all([ ])

}

vuex-store

import Vue from 'vue'
import Vuex from 'vuex'
import createPersist from 'vuex-localstorage'
import packageJson from '../../package.json'

import layout from './modules/layout'
import auth from './modules/auth'
import privilege from './modules/privilege'
import historyBack from './modules/historyBack'

Vue.use(Vuex)

const store = new Vuex.Store({
// actions,
// getters,
modules: {
layout,
auth,
privilege,
historyBack
},

strict: process.env.NODE_ENV !== 'production',

// 使用 vuex-localStorage 持久化页面状态
plugins: [createPersist({
namespace: ${packageJson.name}@${packageJson.version}:store,
expires: 7 * 24 * 60 * 60 * 1e3
})]
})

export default store

vuex-store-module-demo

// initial state
const state = {
value: '',
}

// getters
const getters = {
history: state => state.value,
}

// actions
const actions = {}

// mutations
const mutations = {
history (state, data) {
state.value = data
},
}

export default {
state,
getters,
actions,
mutations
}

vuex-store-use

import store from 'store';

store.commit('history', {value: 1}) //设置值

store.getters.history.value // 读取值

vue watch 及router props

vue 精华 --------------------------------------------------

vue router常用

///this.$route 取参数 ,

this.$route.path

//this.$router 调用方法
this.$router.push()

this.$router.replace()

///--------监听对象事件
watch:{
'object.atr':{
handler(v){
console.log(v)
},
deep:true //深度监听
}
}

///-------------------父 传子 子修改父的值

父页面

子页面
props:{
value:{type:String}
}

this.$emit('input',text)

///--------------------------阻止form提交

// 关于 slot 传参

组件页面

调用插入页面 slot-scope 用传参 一定要写

{{ props.data }}

双向绑定 .sync v-on v-model 区别

sync

子组件
props:['foo']
this.$emit('update:foo',1111)


v-on

methods:{
update(val){
console.log(val)
}
}
子组件
this.$emit('update',1111)


v-model

子组件
props:{
value:{type:String}
}
this.$emit('input',1111)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.