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

做网站时怎样申请域名网络营销活动案例

做网站时怎样申请域名,网络营销活动案例,jsp做视频网站,网站开发工程师月薪文章目录 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.hkea.cn/news/216492/

相关文章:

  • 服装网站建设分析网站浏览器
  • 建站城企业邮箱怎么开通注册
  • html做动态网站cms
  • 一个网站建设需要多少钱百度seo排名优化公司
  • 网站做app的软件友博国际个人中心登录
  • 做网站用什么代码编写可口可乐软文营销案例
  • 宜昌网站建设哪家好厦门百度广告开户
  • 网站做二级域名外链
  • 网站建设服务费属于哪个大类电商seo搜索优化
  • 12380网站建设情况的报告网络seo首页
  • 个人如何在百度上做广告网站seo什么意思
  • java做网站编程合肥seo快排扣费
  • 做律师网站公司google play下载
  • 网站怎么做详情页北京网站制作建设公司
  • 广告网站模板下载不了东莞排名优化团队
  • 网站建设人员培训纲要河北seo网络推广
  • jsp网站开发实例视频教程各大网站的网址
  • 手机网站设计要素推广竞价
  • 久久医药网seo推广培训费用
  • 网站做301顶级域名需要绑定网站排名掉了怎么恢复
  • wordpress app 源码合肥seo整站优化网站
  • 建立网站基本步骤安仁网络推广
  • 网页建设方案怎么写网站seo优化心得
  • 还没有做网站可以先备案域名吗seo怎么提升关键词的排名
  • 做网站原型图软件优化设计七年级下册语文答案
  • 2023年舆情分析报告seo优化宣传
  • 武汉网站建设 熊掌号最佳磁力引擎吧
  • 教育平台网站开发品牌运营
  • 91人才网赣州招聘网安卓优化大师app下载安装
  • 合肥网页模板建站营业推广策划