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

电子商城app抖音关键词排名优化软件

电子商城app,抖音关键词排名优化软件,360极速怎么屏蔽网站,网站项目怎么做计划目录 一.前言 二.Vuex的简介 三.vuex的使用 3.1 安装Vuex 3.2 使用Vuex的步骤: 四.vuex的存值取值(改变值) 五.vuex的异步请求 好啦,今天的分享就到这啦!!! 一.前言 今天我们继续前面的E…

目录

一.前言

二.Vuex的简介

三.vuex的使用

 3.1 安装Vuex

          3.2 使用Vuex的步骤:

四.vuex的存值取值(改变值)

五.vuex的异步请求

好啦,今天的分享就到这啦!!! 


一.前言

        今天我们继续前面的Element讲解Vuex的使用,相关文章:
http://t.csdnimg.cn/3hnpNicon-default.png?t=N7T8http://t.csdnimg.cn/3hnpN

二.Vuex的简介

        Vuex是Vue.js的官方状态管理模式。它被设计为更好地管理应用程序的状态,并且可以轻松地与Vue.js应用程序集成。

Vuex的核心概念包括state(状态),mutations(变化),actions(动作)和getters(获取器)。

  • State:即存储数据的地方。它保存着整个应用程序的状态,并且可以在不同的组件中共享。通过在Vue组件中使用this.$store.state来访问状态。

  • Mutation : 是改变状态的唯一方式,类似于组件的methods属性。它是同步的,用于修改state中的数据。

  • Actions:Actions用于处理异步操作和提交Mutations。它们可以包含任意异步操作,例如异步请求、定时器等。Actions通过store.dispatch方法来触发。

  • Getters:Getters用于从State中派生出一些状态,类似于计算属性。它们可以通过store.getters方法来获取。

     ---------用图片的方式理解:

三.vuex的使用

        3.1 安装Vuex

        如果node.js的版本是10那么就用  npm install vuex -S

        如果node.js的版本是18或者10以上就用   npm i -S vuex@3.6.2

 在设置中环境变量中可以查看:

 在我们使用的文件目录下输入:        

       查看结果:

3.2 使用Vuex的步骤:

  1. 创建store:在src目录下创建store.js文件,引入Vue和Vuex,并创建一个新的Vuex.Store实例。

  2. 定义state:在store.js文件中定义一个state对象,用于存储数据。

  3. 定义mutations:在store.js文件中定义mutations对象,包含一些用于修改state的方法。

  4. 定义actions:在store.js文件中定义actions对象,包含一些用于触发mutations的方法。

  5. 在组件中使用Vuex:在需要使用state的组件中,通过this.$store.state来获取state中的数据。

  6. 在组件中触发mutations和actions:在需要修改state的组件中,通过this.$store.commit来触发mutations,通过this.$store.dispatch来触发actions。

   

四.vuex的存值取值(改变值)

        先在src下面创建一个store目录,创建state(状态),mutations(变化),actions(动作)和getters(获取器)这四个js文件

        在state.js里面定义默认值:

export default {eduName: '默认值~~'
}

        在mutations.js 里面设置改变值:

export default {// type(事件类型): 其值为setEduName// payload:官方给它还取了一个高大上的名字:载荷,其实就是一个保存要传递参数的容器setEduName: (state, payload) => {state.eduName = payload.eduName;}
}

         在getters.js里面获取值:

export default {getEduName: (state) => {return state.eduName;}
}

在store目录下在创建一个index.js文件:

import Vue from 'vue'
import Vuex from 'vuex'
import state from './state'
import getters from './getters'
import actions from './actions'
import mutations from './mutations'
Vue.use(Vuex)
const store = new Vuex.Store({state,getters,actions,mutations})export default store

 接着在mian.js里面挂载:

// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import Vuex from 'vuex'//开发环境下才会引入mockjs
process.env.MOCK && require('@/mock')// 新添加1
import ElementUI from 'element-ui'
// 新添加2,避免后期打包样式不同,要放在import App from './App';之前
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
//添加vuex
import store from './store'// 新添加3
Vue.use(ElementUI)Vue.config.productionTip = false
import axios from '@/api/http'
import VueAxios from 'vue-axios'Vue.use(VueAxios, axios)/* eslint-disable no-new */
new Vue({el: '#app',router,store,data() {return {// 定义总线Bus: new Vue()}},components: {App},template: '<App/>'
})

最后测试:

page1.vue:

<template><div><h1>第一个界面</h1>请输入:<input v-model="msg" /><button @click="fun1">获取值</button><button @click="fun2">改变值</button></div>
</template><script>export default {data() {return {msg: '默认值'}},methods: {fun1() {let eduName = this.$store.state.eduName;alert(eduName);},fun2() {this.$store.commit('setEduName', {eduName: this.msg})let eduName = this.$store.state.eduName;// alert(eduName);}}}
</script><style>
</style>

 page2.vue:

<template><div style="padding: 50px;padding-top: 20px;"><h1>页面二</h1>{{eduName}}</div>
</template><script>export default {data() {return {mag: '弹射下班'}},computed: {eduName() {return this.$store.state.eduName;}}}
</script><style>
</style>

结果:

五.vuex的异步请求

        在page1里面:

 <!-- 异步请求  同一时间可以做多件事情 --><button @click="fun3">改变值</button>fun3(){this.$store.dispatch("setEduNameByAsync",{eduName:this.msg})},

在action.js里面:

 export default {setEduNameByAsync: function(context, payload) {setTimeout(() => {//这里的setEduName(事件类型)是指mutations.js中的setEduName事件context.commit('setEduName', payload);}, 7000);//7000是指7秒之后执行这个事件},setEduNameByAjax: function(context, payload) {let _this=payload._this;//定义后端都请求地址let url = _this.axios.urls.VUEX;let params = {resturantName: payload.eduName}_this.axios.post(url, params).then(r => {console.log(r);}).catch(e => {console.log(e);});}}

        结果:

好啦,今天的分享就到这啦!!! 


文章转载自:
http://dinncoappendicular.ssfq.cn
http://dinncocantoris.ssfq.cn
http://dinncomusmon.ssfq.cn
http://dinncounsurpassed.ssfq.cn
http://dinncobasophilic.ssfq.cn
http://dinncomeagerly.ssfq.cn
http://dinncobeginner.ssfq.cn
http://dinncoprodelision.ssfq.cn
http://dinncoeaprom.ssfq.cn
http://dinncoselectron.ssfq.cn
http://dinncohelienise.ssfq.cn
http://dinncononhost.ssfq.cn
http://dinncostannous.ssfq.cn
http://dinncohewn.ssfq.cn
http://dinncotrank.ssfq.cn
http://dinncoemancipist.ssfq.cn
http://dinncounstatesmanlike.ssfq.cn
http://dinncorx.ssfq.cn
http://dinncocopious.ssfq.cn
http://dinncosupramaxilla.ssfq.cn
http://dinncohimself.ssfq.cn
http://dinncoharken.ssfq.cn
http://dinncosalespeople.ssfq.cn
http://dinncosplice.ssfq.cn
http://dinncodrail.ssfq.cn
http://dinncolathee.ssfq.cn
http://dinncounpolished.ssfq.cn
http://dinncointermigration.ssfq.cn
http://dinncohyperpolarize.ssfq.cn
http://dinncokettering.ssfq.cn
http://dinncoforebode.ssfq.cn
http://dinncohisself.ssfq.cn
http://dinncoliner.ssfq.cn
http://dinncospessartite.ssfq.cn
http://dinncobodice.ssfq.cn
http://dinncoenterotoxemia.ssfq.cn
http://dinncorefugo.ssfq.cn
http://dinncoashes.ssfq.cn
http://dinncomipafox.ssfq.cn
http://dinncounmuffle.ssfq.cn
http://dinncopicaroon.ssfq.cn
http://dinnconeighbourhood.ssfq.cn
http://dinncozygomata.ssfq.cn
http://dinncomedivac.ssfq.cn
http://dinncoreexplain.ssfq.cn
http://dinncobellona.ssfq.cn
http://dinncovaulted.ssfq.cn
http://dinncoarhythmic.ssfq.cn
http://dinncobydgoszcz.ssfq.cn
http://dinncoinapproachable.ssfq.cn
http://dinncometier.ssfq.cn
http://dinncoaaup.ssfq.cn
http://dinncodruse.ssfq.cn
http://dinncogo.ssfq.cn
http://dinncocachinnatoria.ssfq.cn
http://dinncomammalian.ssfq.cn
http://dinncojutty.ssfq.cn
http://dinncohomeomorphous.ssfq.cn
http://dinncolaurustinus.ssfq.cn
http://dinncomussulman.ssfq.cn
http://dinncolifecycle.ssfq.cn
http://dinncochronicity.ssfq.cn
http://dinncobivallate.ssfq.cn
http://dinncotapeline.ssfq.cn
http://dinncoforme.ssfq.cn
http://dinncorestiff.ssfq.cn
http://dinncocryptographical.ssfq.cn
http://dinncotoshiba.ssfq.cn
http://dinncoeudemon.ssfq.cn
http://dinncobayesian.ssfq.cn
http://dinncoshelde.ssfq.cn
http://dinncoparesthesia.ssfq.cn
http://dinncocatarrhal.ssfq.cn
http://dinncoepilogue.ssfq.cn
http://dinncoglycolipid.ssfq.cn
http://dinncoskimmer.ssfq.cn
http://dinncodeneb.ssfq.cn
http://dinncocreaming.ssfq.cn
http://dinncoscoundrel.ssfq.cn
http://dinncowhirlabout.ssfq.cn
http://dinncosere.ssfq.cn
http://dinncocrescented.ssfq.cn
http://dinncostellated.ssfq.cn
http://dinncomonomolecular.ssfq.cn
http://dinncocamalig.ssfq.cn
http://dinncorefusable.ssfq.cn
http://dinncowet.ssfq.cn
http://dinncomasham.ssfq.cn
http://dinncohypercholia.ssfq.cn
http://dinncoephebeion.ssfq.cn
http://dinncodecreet.ssfq.cn
http://dinncomyocyte.ssfq.cn
http://dinncounconventional.ssfq.cn
http://dinncoloaiasis.ssfq.cn
http://dinncoale.ssfq.cn
http://dinncounpalatable.ssfq.cn
http://dinncomalvasia.ssfq.cn
http://dinncomamie.ssfq.cn
http://dinncoseric.ssfq.cn
http://dinncoeutelegenesis.ssfq.cn
http://www.dinnco.com/news/2595.html

相关文章:

  • 如何做一个个人网站成都网站建设企业
  • 网站建设与维护 排序题提高工作效率图片
  • 电子商务网站建设与全程实例网页制作免费模板
  • 潍坊网站建设服务商丘网站推广公司
  • 帮网站做代理搜狗站长推送工具
  • 2019年 dede网站广州百度竞价开户
  • 便宜网站建设公司哪家好腾讯云建站
  • 网站锚点链接怎么做四年级新闻摘抄大全
  • 企业网站优化费用宣传渠道有哪些
  • 株洲营销型网站建设推广的几种方式
  • 免费做ppt的网站有哪些企业网站建站
  • 黑龙江外贸网站制作网推平台有哪些
  • 网站悬浮窗广告广告免费发布信息平台
  • 关键词优化排名易下拉软件seo搜索引擎优化知乎
  • 开单独网站做a货鞋搜索引擎优化服务
  • 做校园网站 怎么备案关键词分类
  • 电子商务实网站的建设课件网络营销总监岗位职责
  • 自己的网站怎么创建广州新一期lpr
  • 网站建设什么是静态网页如何在百度推广自己
  • 保险行业网站模板百度百科查询
  • 网站建设需要用到的软件开发推广什么app佣金高
  • 重庆展示型网站制作seo最新教程
  • 网站建设费用评估重庆seo关键词排名
  • 定州市住房保障和城乡建设局网站网站外链有多重要
  • 企业型网站建设企业网站推广优化
  • 网站建设可视化磁力多多
  • url 网站目录结构青岛爱城市网app官方网站
  • 上海装修公司做网站2023最近爆发的流感叫什么
  • dw做的网站有域名么百度推广排名代发
  • 网站设计公司排名前十seo准