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

asp的公司网站扬中人才

asp的公司网站,扬中人才,健身俱乐部网站开发文档,263云通信官方网站更改 Vuex 的 store 中的状态的唯一方法是提交 mutation。Vuex 中的 mutation 非常类似于事件#xff1a;每个 mutation 都有一个字符串的 事件类型 (type) 和 一个 回调函数 (handler)。 接下来我们还是用上一篇文章在state中存放的count为例#xff0c;来看利用Mutation修改… 更改 Vuex 的 store 中的状态的唯一方法是提交 mutation。Vuex 中的 mutation 非常类似于事件每个 mutation 都有一个字符串的 事件类型 (type) 和 一个 回调函数 (handler)。 接下来我们还是用上一篇文章在state中存放的count为例来看利用Mutation修改state的count属性。 利用commit来触发mutation函数 在mutation函数中添加count的add函数 const mutations {addNum (state) {state.num},add (state) {state.count 2} } export default mutations 在组件中使用mutation进行实现叠加器 templatediv classmutationp{{ count }}/pbutton clickaddCountADD/button/div /templatescript import store from /store/store export default {computed: {count () {return this.$store.state.count}},methods: {addCount () {store.commit(add)}} } /script Mutation的载荷payload 你可以向store.commit传入额外的参数即mutation的载荷payload我们还是以上面累加器的例子来实现mutation函数的传参来动态定义累加的数量。 在mutation.js中修改add方法 const mutations {addNum (state) {state.num},add (state, n) {state.count n} }export default mutations 在组件中store.commit如何传参 templatediv classmutationp{{ count }}/pbutton clickaddCountADD/button/div /templatescript import store from /store/store export default {computed: {count () {return this.$store.state.count}},methods: {addCount () {store.commit(add, 5)}} } /script在mutation传参载荷可以传递一个参数也可以传递一个对象。让我们修改下上面的例子 mutation.js文件中修改如下 const mutations {addNum (state) {state.num},add (state, payload) {state.count payload.amount} }export default mutations 组件中修改如下 templatediv classmutationp{{ count }}/pbutton clickaddCountADD/button/div /templatescript import store from /store/store export default {computed: {count () {return this.$store.state.count}},methods: {addCount () {store.commit(add, { amount: 10 })}} } /script 在store.commit中可以进行对象风格的提交 依据上面的例子我们将组件中内容修改如下 templatediv classmutationp{{ count }}/pbutton clickaddCountADD/button/div /templatescript import store from /store/store export default {computed: {count () {return this.$store.state.count}},methods: {addCount () {store.commit({type: add,amount: 8})}} } /script 使用常量替代 Mutation 事件类型 使用常量替代mutation事件类型在各种Flux实现中是很常见的模式。这样可以使 linter之类的工具发挥作用同时把这些常量放在单独的文件中可以让你的代码合作者对整个项目包含的mutation一目了然。这在在需要多人协作的大型项目中这会很有帮助。 我们在store中新建mutation-types.js文件文件内容如下 export const SOME_MUTATION SOME_MUTATION在mutation.js文件内容如下 import { ADD } from ./mutation-types const mutations {addNum (state) {state.num},[ADD] (state) {state.count} }export default mutations 在组件中内容和之前一致 templatediv classmutationp{{ count }}/pbutton clickaddCountADD/button/div /templatescript import store from /store/store export default {computed: {count () {return this.$store.state.count}},methods: {addCount () {store.commit(add)}} } /script 在组件中使用this.$store全局属性来触发mutation函数 templatediv classmutationp{{ count }}/pbutton clickaddADD/button/div /templatescript export default {computed: {count () {return this.$store.state.count}},methods: {add () {this.$store.commit(add)}} } /script 在组件中使用mapMutations辅助函数 templatediv classmutationp{{ count }}/pbutton clickaddADD/button/div /templatescript import { mapMutations } from vuex export default {computed: {count () {return this.$store.state.count}},methods: {...mapMutations([add])} } /script Mutation一条重要的原则就是要记住 mutation 必须是同步函数  转载于:https://www.cnblogs.com/wangshucheng/p/vux-003.html
http://www.pierceye.com/news/102647/

相关文章:

  • 郑州中原区建设局网站公司网站建设素材
  • 企业手机网站源码下载企查查网页版
  • 金科网站建设ps做网站难吗
  • 如何在年报网站上做遗失公告wordpress默认摘要
  • 中国网站服务器哪个好有哪些做公司网站
  • 做宠物的网站有哪些如何做电商生意
  • 具有品牌的常州做网站关于网站建设的广告词
  • 孝感网站推广品牌策划公司都有哪些
  • 保洁公司用哪些网站做推广wordpress aj提交评论
  • 互联网金融p2p网站建设模板简历模板免费下载网站
  • 绍兴建设网站制作3免费做网站
  • 东莞运营推广网站建设费用wordpress 单栏 主题
  • 律师事务所网站制作WordPress 经典博客
  • 建立网站功能wordpress微博头条
  • 多就能自己做网站取名网站怎么做
  • 网站域名百度云网站环境建设国家城乡建设规划部网站
  • 网站设计的实例wordpress 微博备份
  • 网络推销黑河网站seo
  • 天津市建设工程管理总队网站wordpress 自媒体模版
  • 用网站做宣传的方案郴州买房网站
  • 微信网站前景wordpress 主题开发教程
  • 基于php旅游网站的毕业设计太原网站建设主页
  • 硅谷网站开发薪酬网站建设 数据可视化
  • 绍兴网站建设设计制作高端的网站开发公司
  • 网站建设包括内容南阳网站建设价格
  • 天津平台网站建设哪里好深圳网络营销推广专员
  • 手机网站建设哪家好嘉定房地产网站建设
  • 酒店网站建设需求分析wordpress 文档模板
  • 品牌微信网站定制wordpress企业cms
  • 郑州网站推广效果免费的个人网页