vue component created没有触发_Vue 全局数据管理-Vuex
Vuex就是專(zhuān)為 Vue.js 應(yīng)用程序開(kāi)發(fā)的數(shù)據(jù)讀寫(xiě)工具
參考官方文檔
開(kāi)始 | Vuex?vuex.vuejs.org與vue不同它需要通過(guò)commit來(lái)觸發(fā)事件
Vue.use(Vuex)會(huì)在Vue的原型上綁定一個(gè)共用屬性,把store綁到Vue.prototype上
Vue.prototype.$store = store
從Vue組件里獲取Vuex的狀態(tài),使用計(jì)算屬性
Vuex小結(jié)
在組件里使用它時(shí),讀的時(shí)候分為使用對(duì)象語(yǔ)法還是類(lèi)語(yǔ)法,對(duì)象語(yǔ)法就使用computed,
this.$store.state.count使用類(lèi)語(yǔ)法(JS/TS)
get如果要寫(xiě)這個(gè)API的時(shí)候使用$store配合commit
this.$store.commit('xxx',payload)//payload是一個(gè)普通值或者對(duì)象此時(shí)無(wú)法獲取commit的返回值,如何去獲取?
this.$store.commit('setTag')然后在
const store = new Vuex.Store({state:{count:0;tag:undefined;}, mutations:{addCount(state){state.count+=1} }再去讀
store.state.tag注意在安裝的時(shí)候
1、Vue.use(Vuex)
2、要把store傳進(jìn)去
new Vue({store, })在ts中使用mixins參考vue class component
Extend and Mixins | Vue Class Component?class-component.vuejs.org// mixins.js import Vue from 'vue' import Component from 'vue-class-component'// You can declare mixins as the same style as components. @Component export class Hello extends Vue {hello = 'Hello' }@Component export class World extends Vue {world = 'World' }使用
import Component, { mixins } from 'vue-class-component' import { Hello, World } from './mixins'// Use `mixins` helper function instead of `Vue`. // `mixins` can receive any number of arguments. @Component export class HelloWorld extends mixins(Hello, World) {created () {console.log(this.hello + ' ' + this.world + '!') // -> Hello World!} }在Labels.vue和Tags.vue里都使用過(guò)了createTag因此可以使用mixins
總結(jié)
以上是生活随笔為你收集整理的vue component created没有触发_Vue 全局数据管理-Vuex的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python爬取抖音用户数据_pytho
- 下一篇: chart.js 饼图显示百分比_Ech