javascript - Rename Vue mapState state - Stack Overflow

In my puted, I have two "loading" states that I want to track. Is there a way to add an alias

In my puted, I have two "loading" states that I want to track. Is there a way to add an alias to the other state with this syntax?

  puted: {
    ...mapState('barcodes', ['barcodes', 'loading', 'pagination']),
    ...mapState('users', ['user', 'loading']), // add an alias for this "loading"
  }

In my puted, I have two "loading" states that I want to track. Is there a way to add an alias to the other state with this syntax?

  puted: {
    ...mapState('barcodes', ['barcodes', 'loading', 'pagination']),
    ...mapState('users', ['user', 'loading']), // add an alias for this "loading"
  }
Share Improve this question asked Oct 25, 2021 at 7:39 patrick_starpatrick_star 731 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

mapState has supported an object way, something like: (Specific alias for only 1 field)

puted: {
  ...mapState('barcodes', {
    barcodesLoading: state => state.loading,
  })
}

Or by namespace: (If you want to wrap all user state into the userData namespace)

puted: {
  ...mapState({
      barcodeData: 'barcodes',
      userData: 'users'
  })
}

on Template:

<div>{{barcodeData.loading}}</div>

There is another thread for your reference:

vuex namespaced mapState with multiple modules

I'm not absolutely sure, because I can't check it out right now. But AFAIK you should just try this:

puted: {
    ...mapState('barcodes', {barcodes:'barcodes', alias1:'loading', pagination:'pagination'}),
    ...mapState('users', {user:'user', alias2:'loading'}), // add an alias for this "loading"
  }

I.e. use object instead of array.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745300926a4621429.html

相关推荐

  • javascript - Rename Vue mapState state - Stack Overflow

    In my puted, I have two "loading" states that I want to track. Is there a way to add an alias

    21小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信