zoukankan      html  css  js  c++  java
  • [Nuxt] Add Arrays of Data to the Vuex Store and Display Them in Vue.js Templates

    You add array of todos to the store simply by adding them to the state defined in your store/index.js file. You can access the array of todos using mapState then loop through and display them with v-for. This lesson walks you through the process of setting up todos in Vuex and displaying them in your Vue.js template.

    store/index.js:

    import Vuex from 'vuex'
    
    const store = () => new Vuex.Store({
      state: {
        todos: [
          {task: 'eat'},
          {task: 'sleep'},
          {task: 'code'}
        ]
      }
    })
    
    export default store

    pages/index.vue:

    <template>
      <article class="pa3 pa5-ns">
        <ul class="list pl0 ml0 center mw6 ba b--light-silver br2">
          <li v-for="todo of todos" class="ph3 pv3 bb b--light-silver">{{todo.task}}</li>
        </ul>
      </article>
    </template>
    
    <script>
      import { mapState } from 'vuex'
    
      export default {
        computed: {
          ...mapState({
            todos: (state) => state.todos
          })
        }
      }
    </script>
  • 相关阅读:
    php 生成唯一订单号
    易语言的软件乱码
    Python正则
    python3.6 安装
    python发送邮件
    python 字典生成sql语句
    python xpath
    Python pip安装Scrapy,报错Twisted
    简单验证码识别
    python mysqldb 返回字典
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7230313.html
Copyright © 2011-2022 走看看