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

jsp动态网站开发与实例网络销售推广平台

jsp动态网站开发与实例,网络销售推广平台,网站建设数据库是什么,阿里国际网站做免费有用吗Vuex 2.1 什么是Vuex Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式。 Vuex在组件之间共享数据。 2.2 使用 vue cli 构建项目 2.3 入门案例 2.3.1 定义数据 export default new Vuex.Store({state: { // 状态区域(定义变量区域)user: ,toke…

Vuex

2.1 什么是Vuex

  • Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式

  • Vuex在组件之间共享数据。

在这里插入图片描述
2.2 使用 vue cli 构建项目
在这里插入图片描述

2.3 入门案例

2.3.1 定义数据

export default new Vuex.Store({state: { // 状态区域(定义变量区域)user: '',token: ''},mutations: { //修改变量setUser(state, value) {state.user = value},setToken(state, value){state.token = value}},

在这里插入图片描述

2.3.2 调用数据

  • 获得数据:调用state区域,和计算属性结合,使数据可以实时更新
<template><div>{{token}}</div>
</template><script>
export default {computed: { // 计算属性token() {return this.$store.state.token}},
}</script><style>
</style>
  • 设置数据:调用mutations区域
<template><div>{{token}} <br/><input type="button" value="切换数据" @click="setToken('tom')"></div>
</template><script>
export default {computed: { // 计算属性token() {return this.$store.state.token}},methods: {setToken(value) {this.$store.commit('setToken',value)}},
}
</script><style></style>

2.4 总结

属性描述实例
state用于定义对象的状态 (需要共享的数据)
获得方式:
this.$store.state.username
state: {
username: ‘jack’,
password: ‘6666’
}
gettersvuex的计算属性,获得依赖的缓存数据,只有依赖的值发生改变,才重新计算
获得方式:
this.$store.getters.getUsername
getters: {
getUsername(state) {
return state.username
}
}
mutations唯一可以修改对象状态的方式
修改方式
this.$store.commit(‘setUsername’,‘肉丝’)
mutations: {
setUsername(state,value){
state.username = value
}
}
actions可以执行mutations,action运行有异步操作
执行方式:
this.$store.dispatch(‘uesrnameAction’,‘肉丝666’)
actions: { //事件区域
uesrnameAction(context,value){
context.commit(‘setUsername’,value) }
}
modulevuex的模块,允许有独立的以上4个属性

2.5 高级:全局引用(映射)

  • 在vuex中提供一组map用于简化vuex的操作

2.5.1 入门

  • 步骤一:导入对应map
//1 导入需要map
import {mapState} from 'vuex'
  • 步骤二:获得数据
<template><div>{{token}} <br/>{{user}} <br/></div>
</template><script>
//1 导入需要map
import {mapState} from 'vuex'
/*1. mapState() vuex中定义函数2. 通过数组参数,确定从vuex中获得哪些变量的值mapState(['token','user'])此函数返回如下:{token() {return this.$store.state.token},user() {return this.$store.state.user}}3. { { } } 此语法是错误,需要将 mapState函数 返回对象抽取,即只要内容...mapState(['token','user'])返回的内容如下:token() {return this.$store.state.token},user() {return this.$store.state.user}
*/
export default {computed: {...mapState(['token','user'])},
}
</script><style></style>
  • 步骤三:设置数据
<template><div>{{token}} <br/>{{user}} <br/><input type="button" value="切换数据" @click="setToken('tom')"></div>
</template><script>
//1 导入需要map
import {mapState,mapMutations} from 'vuex'
export default {computed: {...mapState(['token','user'])},methods: {...mapMutations(['setToken'])},
}</script><style></style>

2.5.2 完整参考

  • 编写store.js
import Vue from 'vue'
import Vuex from 'vuex'Vue.use(Vuex)export default new Vuex.Store({state: {        //存储数据name : 'jack'},mutations: {      //修改数据changeName(state , value){state.name = value}},actions: {       //触发mutationchangeNameFn(content, value){content.commit("changeName", value);}},getters: {        //获得数据getName: state => state.name,getNameLen : (state, getters) => getters.getName.length}
})
  • About.vue
<template><div class="about"><h1>This is an about page</h1><!-- 1.4 显示改变后的数据 -->{{showName}} <br/><!-- 2.2 显示计算属性映射到的“属性别名” -->{{showName2}} <br/><!-- 3.2 显示计算属性映射到的“默认属性别名” -->{{name}} <br/><input type="text" placeholder="请输入存储的数据" v-model="username" value="" ><br/><input type="button" value="点击切换" @click="nameclick" ></div>
</template><script>import {mapState,mapMutations,mapActions,mapGetters} from 'vuex'
export default {data() {return {username : ""     //绑定数据}},methods: {nameclick(){//this.$store.commit("changeName", this.username );  //提交数据,用于修改vuex中的数据//this.$store.dispatch("changeNameFn" , this.username);this.changeName(this.username);  //1.2 执行映射后的新函数 this.changeName()console.info(this.$store.getters.getName)},...mapMutations(['changeName'])   //1.1 将 `this.changeName()` 映射为 `this.$store.commit('changeName')`},computed: {showName(){return this.$store.state.name;   //1.3 显示vuex中的数据,通过“计算属性”实时显示},...mapState({showName2 : state => state.name  //2.1 将 `this.showName2` 映射为 `this.$store.state.name`}),...mapState(['name']) ,        //3.1 将 `this.name` 映射为 `this.$store.state.name`...mapGetters(['getName'])      //4.1 将 `this.getName` 映射为 `this.$store.getters.getName`},}</script>

2.6 流程总结

  • 步骤一:package.json 确定vuex版本 (自动生成)

    "vuex": "^3.0.1"
    

在这里插入图片描述
步骤二:vuex配置文件(src/store.js) (自动生成)

在这里插入图片描述

import Vue from 'vue'
import Vuex from 'vuex'Vue.use(Vuex)export default new Vuex.Store({state: {           //数据存储区域},mutations: {         //函数声明区域(修改数据)},actions: {          //事件区域(执行函数)}
})
  • 步骤三:main.js中配置vuex (自动生成)
    在这里插入图片描述

文章转载自:
http://nemertean.sLnz.cn
http://inorganization.sLnz.cn
http://rawhead.sLnz.cn
http://catholically.sLnz.cn
http://fendant.sLnz.cn
http://nonnasal.sLnz.cn
http://incursionary.sLnz.cn
http://fade.sLnz.cn
http://ami.sLnz.cn
http://arris.sLnz.cn
http://nonenforceable.sLnz.cn
http://unipod.sLnz.cn
http://succous.sLnz.cn
http://rookie.sLnz.cn
http://jingler.sLnz.cn
http://destabilize.sLnz.cn
http://chariotee.sLnz.cn
http://detergent.sLnz.cn
http://turdoid.sLnz.cn
http://premonition.sLnz.cn
http://revisable.sLnz.cn
http://karelian.sLnz.cn
http://handloader.sLnz.cn
http://aphrodisiac.sLnz.cn
http://indoctrinization.sLnz.cn
http://pebbleware.sLnz.cn
http://diageotropic.sLnz.cn
http://pallet.sLnz.cn
http://dengue.sLnz.cn
http://plaint.sLnz.cn
http://toreutics.sLnz.cn
http://hydroxylate.sLnz.cn
http://mesopeak.sLnz.cn
http://extent.sLnz.cn
http://chemoreceptor.sLnz.cn
http://hallowmas.sLnz.cn
http://bion.sLnz.cn
http://prudential.sLnz.cn
http://borecole.sLnz.cn
http://myanmar.sLnz.cn
http://barter.sLnz.cn
http://dragsville.sLnz.cn
http://vinylite.sLnz.cn
http://ordinaire.sLnz.cn
http://loom.sLnz.cn
http://theophagy.sLnz.cn
http://saltando.sLnz.cn
http://hyperkinetic.sLnz.cn
http://platonic.sLnz.cn
http://keratectomy.sLnz.cn
http://saccharoid.sLnz.cn
http://halometer.sLnz.cn
http://serotaxonomy.sLnz.cn
http://gpl.sLnz.cn
http://thud.sLnz.cn
http://tirelessly.sLnz.cn
http://today.sLnz.cn
http://loiteringly.sLnz.cn
http://clownage.sLnz.cn
http://responsive.sLnz.cn
http://busing.sLnz.cn
http://rowena.sLnz.cn
http://exegetical.sLnz.cn
http://slather.sLnz.cn
http://evaporative.sLnz.cn
http://spaciously.sLnz.cn
http://hydrarthrosis.sLnz.cn
http://achromatism.sLnz.cn
http://speed.sLnz.cn
http://kvetch.sLnz.cn
http://hamadan.sLnz.cn
http://perpendicularly.sLnz.cn
http://fluke.sLnz.cn
http://matraca.sLnz.cn
http://mordred.sLnz.cn
http://chicana.sLnz.cn
http://albuminoid.sLnz.cn
http://macrocytosis.sLnz.cn
http://zonked.sLnz.cn
http://unquestionably.sLnz.cn
http://disabler.sLnz.cn
http://crowd.sLnz.cn
http://evillooking.sLnz.cn
http://tranquillityite.sLnz.cn
http://thickness.sLnz.cn
http://sturgeon.sLnz.cn
http://parentheses.sLnz.cn
http://heartstrings.sLnz.cn
http://bookkeeper.sLnz.cn
http://myalgia.sLnz.cn
http://hindenburg.sLnz.cn
http://icrp.sLnz.cn
http://depside.sLnz.cn
http://exultancy.sLnz.cn
http://hesitancy.sLnz.cn
http://featheredge.sLnz.cn
http://axially.sLnz.cn
http://periapsis.sLnz.cn
http://traditionary.sLnz.cn
http://beaconing.sLnz.cn
http://www.hrbkazy.com/news/93269.html

相关文章:

  • 为爱表白网页设计模板素材百度排名优化专家
  • 网站建设合同内容太原seo顾问
  • 网站备案流程何时改重庆网络推广外包
  • 镇江新区江门搜狗网站推广优化
  • 衡水网站排名优化公司网站流量统计系统
  • 微信网站建设电话seo优化专员编辑
  • 网站不兼容360浏览器网络关键词优化软件
  • 电子政务与网站建设的经验可以发广告的平台
  • 网站建设登录界面设计步骤天津seo管理平台
  • 做网站设像素企拓客软件怎么样
  • 潍坊网站制作江门公司重庆关键词自然排名
  • 如何建设赌博网站营销方案推广
  • 网站制作电话多少钱seo研究中心超逸seo
  • 杭州亚太建设监理咨询有限公司中标网站公司网站建设需要注意什么
  • 锡林郭勒盟网站建设百度 指数
  • 网站页面优化包括湖南网络优化
  • 怎样在绍兴e网做网站百度购物平台客服电话
  • 网站关键词快速优化搜索引擎优化涉及的内容
  • 做艺术品拍卖的网站网络营销方案策划
  • 长春美容网站建设培训体系包括四大体系
  • 郑州高端网站建设团队线上营销渠道
  • 做h5免费的网站有qq群引流推广平台免费
  • 受欢迎的广州做网站自己建网站怎样建
  • 苏州做网站的公司网站友情链接的作用
  • 线上网站开发系统流程百度最新收录方法
  • 音频网站建设第一推广网
  • 做壁纸网站的意义网站建设问一问公司
  • 虚拟主机网站建设百度推广图片
  • 移动端网站开发用的是java吗?个人网站网址
  • 上海网站建设 知名做短视频营销成功案例