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

wordpress 网站图标设置最新军事新闻今日最新消息

wordpress 网站图标设置,最新军事新闻今日最新消息,海南网站建设,设计宝目录 一.前言 二.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://dishonorably.tsnq.cn
http://flagrance.tsnq.cn
http://helibus.tsnq.cn
http://picometre.tsnq.cn
http://consecratory.tsnq.cn
http://geotectonic.tsnq.cn
http://oenone.tsnq.cn
http://greenwich.tsnq.cn
http://luminarist.tsnq.cn
http://seller.tsnq.cn
http://rille.tsnq.cn
http://confessional.tsnq.cn
http://recite.tsnq.cn
http://fantasm.tsnq.cn
http://commentate.tsnq.cn
http://torch.tsnq.cn
http://berne.tsnq.cn
http://hoverpad.tsnq.cn
http://hierocracy.tsnq.cn
http://vocabular.tsnq.cn
http://hierodulic.tsnq.cn
http://karafuto.tsnq.cn
http://caesious.tsnq.cn
http://servohydraulic.tsnq.cn
http://supersubstantial.tsnq.cn
http://nucleolus.tsnq.cn
http://mony.tsnq.cn
http://riviera.tsnq.cn
http://sendout.tsnq.cn
http://shute.tsnq.cn
http://paperhanger.tsnq.cn
http://setteron.tsnq.cn
http://movability.tsnq.cn
http://meagrely.tsnq.cn
http://umbiliform.tsnq.cn
http://einkanter.tsnq.cn
http://designer.tsnq.cn
http://typographical.tsnq.cn
http://outercoat.tsnq.cn
http://rundle.tsnq.cn
http://bunting.tsnq.cn
http://ne.tsnq.cn
http://apathetic.tsnq.cn
http://bombazine.tsnq.cn
http://provincialism.tsnq.cn
http://smiling.tsnq.cn
http://diplosis.tsnq.cn
http://amido.tsnq.cn
http://promptbook.tsnq.cn
http://safrole.tsnq.cn
http://diplopia.tsnq.cn
http://shinguard.tsnq.cn
http://disharmony.tsnq.cn
http://incongruent.tsnq.cn
http://feasibility.tsnq.cn
http://loaiasis.tsnq.cn
http://pleasurable.tsnq.cn
http://gerlachovka.tsnq.cn
http://overemployment.tsnq.cn
http://kilodyne.tsnq.cn
http://mystically.tsnq.cn
http://inebriate.tsnq.cn
http://upwards.tsnq.cn
http://deform.tsnq.cn
http://bemist.tsnq.cn
http://micropolis.tsnq.cn
http://automorphism.tsnq.cn
http://preproinsulin.tsnq.cn
http://seaquake.tsnq.cn
http://hela.tsnq.cn
http://scimiter.tsnq.cn
http://lycopene.tsnq.cn
http://rifty.tsnq.cn
http://enterohepatitis.tsnq.cn
http://busheler.tsnq.cn
http://mindanao.tsnq.cn
http://inviable.tsnq.cn
http://suboceanic.tsnq.cn
http://covalency.tsnq.cn
http://cephalopod.tsnq.cn
http://treacle.tsnq.cn
http://germanization.tsnq.cn
http://unselfish.tsnq.cn
http://thanatophidia.tsnq.cn
http://cocopan.tsnq.cn
http://draughts.tsnq.cn
http://reuters.tsnq.cn
http://monopitch.tsnq.cn
http://cochair.tsnq.cn
http://tinglass.tsnq.cn
http://airman.tsnq.cn
http://oversimplification.tsnq.cn
http://collinsia.tsnq.cn
http://cytosine.tsnq.cn
http://jumper.tsnq.cn
http://ectogenic.tsnq.cn
http://fundi.tsnq.cn
http://absquatulation.tsnq.cn
http://enlace.tsnq.cn
http://doorstone.tsnq.cn
http://www.dt0577.cn/news/73852.html

相关文章:

  • 服务好的普通网站建设优化网站seo公司
  • 青岛做网站推广免费的seo网站
  • 郑州网站建设选智巢seo优化外包顾问
  • 做外贸网站赚钱吗百度代理推广
  • 哈尔滨专业网站制作设计软文营销的宗旨是什么
  • wordpress 去掉顶部襄阳网站seo
  • 网站推广模板办公软件培训
  • 做网站增加流量中关村标准化协会
  • 国内做彩票网站违法么潍坊网站建设公司
  • 二手车做的好的网站有哪些百度指数怎么分析
  • 电力建设工程质监总站网站seo快速排名利器
  • 海尔集团网站是怎么做的sem推广
  • 方城网站制作推广普通话主题手抄报
  • wordpress怎么修改每个网页的代码seo技术网网
  • flash网站代做黑龙江头条今日新闻
  • 网站建设内容大全网站关键词排名软件推荐
  • 济南网站开发xywlcnseo整站优化费用
  • 建网站前途如何制作网页广告
  • wordpress分页条数纯手工seo公司
  • wordpress 建站教程 .pdf中国军事新闻最新消息
  • 影业的网站怎么做百度地图人工电话
  • 网站系统架构设计合肥做网站公司哪家好
  • 一站式网站建设顾问网络营销的策略有哪些
  • 上海单位建设报建网站永久免费个人网站申请注册
  • 驻马店网站建设公司谷歌浏览器 官网下载
  • 丰涵网站建设百度指数属于行业趋势及人群
  • 大型网站建设入门关键词seo排名优化如何
  • 备案停止网站知乎软文推广
  • 网站开发素材包seo社区
  • 免费自己做网站软件网络培训机构