vuex简单使用模板,一分钟快速上手,新手入门

这篇博客提供了一个经过整理的Vuex使用模板,适合新手快速上手。包含testPage_1.vue、testPage_2.vue和testPage_3.vue三个页面,分别展示了直接访问store、模块化及map辅助函数的用法。同时,详细介绍了store中的index.js状态管理配置。
摘要由CSDN通过智能技术生成

经过我自己整理过后的vuex的使用模板:https://github.com/cenmen/vuex-store-typical-demo.git

项目主要文件有:testPage_1.vue,testPage_2.vue,testPage_3.vue,store中的index.js

testPage_1.vue:使用最直接的方法访问store

testPage_2.vue:modules 模块化 以及 组件中引入 mapGetters、mapActions 和 mapStates的使用

testPage_3.vue:使用map辅助函数的方法访问store

index.js:状态管理

下面直接贴出代码:

testPage_1.vue:

<template>
  <div class="testPage_1">
    <h1>welcome to testPage_1</h1>
    <h1>'使用最直接的方法访问store'</h1>
    <h1>this.$store.state.count: {
  {this.$store.state.count}}</h1> <!-- 直接用state访问状态 -->
    <h1>getCount: {
  {getCount}}</h1>
    <!-- <h1>{
  {this.$store.getters.getCount}}</h1> -->
    <h1>getDoneTodos: {
  {getDoneTodos}}</h1>
    <h1>text in getTodoById: {
  {getTodoById.text}}</h1>
    <button @click="addCount">+1</button>
    <input v-model="number"><button @click="addNumCount(number)">+n</button>
    <h1>number : {
  {number}}</h1>


  </div>
</template>

<script>
export default {
  name: 'testPage_1',
  data () {
    return {
      number:21,
    }
  },
  computed:{
     getCount(){ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值