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

电脑做系统哪个网站比较好用郑州网站建设方案

电脑做系统哪个网站比较好用,郑州网站建设方案,深圳瑞捷成立新公司,规划案例网站昨天学了插槽,但是没有即笔记了 今天的是vuex 总体来说,vuex就是一个共享单车,每个人都可以使用他,也可也对他进行反馈。即把一个数据列为vuex,然后每个组件可以使用这个对象,也可也反过来反馈他 这一个设…

昨天学了插槽,但是没有即笔记了

今天的是vuex

总体来说,vuex就是一个共享单车,每个人都可以使用他,也可也对他进行反馈。即把一个数据列为vuex,然后每个组件可以使用这个对象,也可也反过来反馈他

这一个设计是将A组件的一个数据作为公共来共享

求和案例,纯vue版

APP.vue

<template><div class="container"><Count/></div>
</template><script>import Count from './components/Count'export default {name:'App',components:{Count}}
</script>

Count.vue

<template><div><h1>当前求和为:{{sum}}</h1><select v-model.number="n"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><button @click="increment">+</button><button @click="decrement">-</button><button @click="incrementOdd">当前求和为奇数再加</button><button @click="incrementWait">等一等再加</button></div>
</template><script>export default {name:'Count',data() {return {n:1, //用户选择的数字sum:0 //当前的和}},methods: {increment(){this.sum += this.n},decrement(){this.sum -= this.n},incrementOdd(){if(this.sum % 2){this.sum += this.n}},incrementWait(){setTimeout(()=>{this.sum += this.n},500)},},}
</script><style>button{margin-left: 5px;}
</style>

这一个是当使用vuex来设计时

vuex原理

store(其实就是下图Vuex):Actions,Mutations,State的父亲,它们三个之间的状态转换(灰色箭头的api)由store提供(store.dispatch,store.commit等等)

Actions:一个普普通通的Object类型对象,vc的改变会先通过store.dispatch()将值传递给action。然后经由action通过store.commit()发送给Mutations。

Actions还可以通过ajax和后端交互,就是下图中的Backend API,通过后端接口拿数据,也是组装到Action中

如果不调用Backend API,VC可以直接将数据交给Mutations,绕开Actions。也就是说Actions是可以跳过的

Mutations(n. 突变,变更):它是一个Object类型的对象。负责真正处理,加工修改数据,处理完成后将处理完成的数据传入State中

Vue的开发工具,Devtools,监测的就是Mutations里的数据

State:也是一个Object类型的对象,vuex会将里面的数据进行渲染,还给VC,更新VC

VUEX的求和案例

main.js

import Vue from 'vue'
import App from './App.vue'
//引入vuex
import Vuex from 'vuex'
//引入store
import store from './store'Vue.config.productionTip = falsenew Vue({el:"#app",render: h => h(App),store,beforeCreate(){Vue.prototype.$bus = this}
})

APP.vue

<template><div class="container"><Count/></div>
</template><script>import Count from './components/Count'export default {name:'App',components:{Count}}
</script>

Count.vue

<template><div><h1>当前求和为:{{$store.state.sum}}</h1><select v-model.number="n"><option value="1">1</option><option value="2">2</option><option value="3">3</option></select><button @click="increment">+</button><button @click="decrement">-</button><button @click="incrementOdd">当前求和为奇数再加</button><button @click="incrementWait">等一等再加</button></div>
</template><script>export default {name:'Count',data() {return {n:1, //用户选择的数字}},methods: {increment(){this.$store.dispatch('jia',this.n)},decrement(){this.$store.dispatch('jian',this.n)},incrementOdd(){this.$store.dispatch('jiaOdd',this.n)},incrementWait(){this.$store.dispatch('jiaWait',this.n)	},},mounted(){console.log('Count',this)}}
</script><style>button{margin-left: 5px;}
</style>

index.js

//该文件用于创建VUex中最为核心的storeimport Vue from 'vue'//引入Vuex
import Vuex from 'vuex'
//应用vuex插件
Vue.use(Vuex)//准备actions -用于响应组件中的动作
const actions ={jia(context,value){console.log('actions中的jia被调用了')context.commit('JIA',value)},jian(context,value){console.log('actions中的jian被调用了')context.commit('JIAN',value)},jiaOdd(context,value){console.log('actions中的jiaOdd被调用了')if(context.state.sum % 2){context.commit('JIA',value)} },jiaWait(context,value){console.log('actions中的jiaWait被调用了')setTimeout(() => {context.commit('JIA',value)}, 500);}
}//准备mutations -用于操作数据(state)
const mutations={JIA(state,value){console.log('mutations中的JIA被调用了')state.sum +=value},JIAN(state,value){console.log('mutations中的JIAN被调用了')state.sum -=value},
}//准备state -用于存储数据
const state ={sum:0 //当前的和 
}//创建并暴露store
export default new Vuex.Store({actions,mutations,state,
})

http://www.15wanjia.com/news/39802.html

相关文章:

  • 平板室内装修设计软件宁波网站优化公司电话
  • wordpress 用户站点独立站建站需要多少钱
  • 怎么做可以支付的网站西安seo排名公司
  • jeecg 做网站seo专业优化方法
  • 广州美容网站建设企业网站的推广形式有
  • 做网店网站互联网广告联盟
  • 怎样选择高性价比的建站公司网站维护收费标准
  • seo外链网站谷歌浏览器网页版入口手机版
  • 杭州网站搭建公司新浪体育最新消息
  • 建站资源厦门百度推广怎么做
  • 做地方网站要办什么证互联网平台
  • wap网站 劣势我想找一个营销团队
  • 长春网站选网诚传媒江苏营销型网站建设
  • 科技型中小企业怎么认定seo关键词优化怎么收费
  • 每天自动更新的网站做任务赚佣金的正规平台
  • 为什么网页总是打不开河北百度seo
  • 做网站遇到的困难总结seo 优化一般包括哪些内容
  • 学校网站建设内容设计网站的优化策略方案
  • wordpress 当前栏目idseo智能优化公司
  • 系统开发者选项怎么关关键字排名优化公司
  • 大的网站建设公司优化设计电子课本下载
  • 个人网站做淘宝客违规百度竞价怎么收费
  • 短链接在线工具广州网站seo推广
  • 南宁网站建设mxfsem东莞网站自动化推广
  • 做网站很麻烦吗大连网站建设费用
  • 织梦网站后台打不开市场调研报告范文
  • 宁波专业网站营销谷歌推广运营
  • 厦门网站建设公司排行榜网站制作的费用
  • 网站后台多附件上传百度提交网址入口
  • 甘肃省城乡建设厅网站windows清理优化大师