当前位置: 首页 > news >正文

网站海外seo建设公司网站模版

网站海外seo,建设公司网站模版,阿里巴巴国际站买家版app,新闻发布的网站文章目录 1,入门案例辅助函数 2,mutations传参辅助函数 3,actions辅助函数 4,getters辅助函数 5,模块拆分6,访问子模块的state辅助函数 7,访问子模块的getters辅助函数 8,访问子模块…

文章目录

  • 1,入门案例
    • 辅助函数
  • 2,mutations传参
    • 辅助函数
  • 3,actions
    • 辅助函数
  • 4,getters
    • 辅助函数
  • 5,模块拆分
  • 6,访问子模块的state
    • 辅助函数
  • 7,访问子模块的getters
    • 辅助函数
  • 8,访问子模块的mutations
    • 辅助函数
  • 9,访问子模块的actions
    • 辅助函数

1,入门案例

安装库。

npm install vuex@3

新建store.js。

import Vue from 'vue'
import Vuex from 'vuex'Vue.use(Vuex)const store = new Vuex.Store({state: {count: 0},mutations: {increment(state) {state.count++}}
})export default store

main.js。

new Vue({render: h => h(App),store
}).$mount('#app')

最后,计数器案例。

<template><h1 @click="add">{{ $store.state.count }}</h1>
</template><script>
export default {name: 'App',methods: {add() {this.$store.commit('increment')}}
}
</script>

效果:

在这里插入图片描述

辅助函数

可以将数据自动变成计算属性。

<template><h1 @click="add">{{ count }}</h1>
</template><script>
import { mapState } from "vuex";
export default {name: 'App',methods: {add() {this.$store.commit('increment')}},computed: {...mapState(['count'])}
}
</script>

2,mutations传参

跟着后面写就行,只能传一个参数。

const store = new Vuex.Store({state: {count: 0},mutations: {increment(state, v) {state.count += v}}
})this.$store.commit('increment', 5)

辅助函数

可以将mutations自动变成方法。

<template><h1 @click="increment(5)">{{ count }}</h1>
</template><script>
import { mapState, mapMutations } from "vuex";
export default {name: 'App',methods: {...mapMutations(['increment'])},computed: {...mapState(['count'])}
}
</script>

3,actions

异步操作数据。

const store = new Vuex.Store({state: {count: 0},mutations: {increment(state, v) {state.count += v}},actions: {incrementAction(context, v) {setTimeout(() => {context.commit('increment', v)}, 1000)}}
})this.$store.dispatch('incrementAction', 5)

辅助函数

可以将actions自动变成方法。

<template><h1 @click="incrementAction(5)">{{ count }}</h1>
</template><script>
import { mapState, mapMutations, mapActions } from "vuex";
export default {name: 'App',methods: {...mapActions(['incrementAction']),...mapMutations(['increment'])},computed: {...mapState(['count'])}
}
</script>

4,getters

派生状态,类似于计算属性。

const store = new Vuex.Store({state: {count: 0},mutations: {increment(state, v) {state.count += v}},actions: {incrementAction(context, v) {setTimeout(() => {context.commit('increment', v)}, 1000)}},getters: {count1(state) {return state.count + "个"}}
})$store.getters.count1 

辅助函数

可以将getters自动变成计算属性。

<template><h1 @click="incrementAction(5)">{{ count1 }}</h1>
</template><script>
import { mapState, mapMutations, mapActions, mapGetters } from "vuex";
export default {name: 'App',methods: {...mapActions(['incrementAction']),...mapMutations(['increment'])},computed: {...mapState(['count']),...mapGetters(['count1'])}
}
</script>

5,模块拆分

新建a.js。

新增了一个配置项namespaced。

export default {namespaced: true,state: {count: 0},mutations: {increment(state, v) {state.count += v}},actions: {incrementAction(context, v) {setTimeout(() => {context.commit('increment', v)}, 1000)}},getters: {count1(state) {return state.count + "个"}}
}

b.js。

export default {namespaced: true,state: {count: 0},mutations: {increment(state, v) {state.count += v}},actions: {incrementAction(context, v) {setTimeout(() => {context.commit('increment', v)}, 1000)}},getters: {count1(state) {return state.count + "个"}}
}

改写store.js。

const store = new Vuex.Store({modules: {a, b}
})

6,访问子模块的state

$store.state.a.count
$store.state.b.count

辅助函数

<template><div><h1>{{ count }}</h1></div>
</template><script>
import { mapState } from "vuex";
export default {computed: {...mapState('a', ['count'])}
}
</script>

7,访问子模块的getters

$store.getters['a/count1']
$store.getters['b/count1']

辅助函数

用法与前面一致。

8,访问子模块的mutations

this.$store.commit('a/increment', 1)

辅助函数

用法与前面一致。

9,访问子模块的actions

this.$store.dispatch('a/incrementAction', 1)

辅助函数

用法与前面一致。

http://www.yayakq.cn/news/998144/

相关文章:

  • 网站设计参考西安网站推广慧创科技
  • 做plc课程设计的网站php多商户商城
  • 网站建设运营必备人员宁海建设局网站
  • 个人网站建设总结wordpress多榜单查询
  • 网站开发包含的项目和分工重庆本地生活网
  • 网站开发技术构架上海网站自然排名优化价格
  • 做棋牌网站空调维修网站建设
  • 手机网站建设运营方案高校网站建设研究意义
  • 长春seo网站排名优化招商团队外包
  • 制作网站好的公司营口工程建设信息网站
  • 三角网站建设网页制作是干什么的
  • 百度云网站开发网站为什么打不开
  • 富阳公司做网站网站建设续费是什么费用
  • 视频播放类网站建设费用网站建设方案书简单
  • 做钻石的网站男女做暖暖的试看网站大全
  • orchard可以做哪些网站网监网站备案
  • 开源网站统计erp二次开发好还是网站开发好
  • 网站建设需要找网站建设公司做吗减肥养生网站建设
  • 学校如何建设网站首页wordpress 占用cpu
  • 通用网址查询网站莱芜金点子2023最新招聘
  • 哈尔滨模板建站定制网站网站建设佰金手指科杰二九
  • 备案号网站下边python做网站
  • 在哪可以找到做网站的无锡网站制作企业
  • 网站流量 用什么表示株洲seo网站优化
  • 免费的网站建设有哪些北京建站模板企业
  • 网站统计网站建设无锡
  • 网站建设流程哪家好石家庄网站建设哪家专业
  • 网站不显示内容网页设计与网站开发教程
  • 台州营销型网站建设租房平台网站开发
  • 如何清空网站空间广州 建网站