• [Nuxt] Display Vuex Data Differently in Each Page of Nuxt and Vue.js


    You often use the same data in different ways across pages. This lesson walks you through setting up multiple pages, retrieving the same data, then displaying it for each page's use-case.

    index.vue:

    <template>
      <div>
        <form @submit.prevent="add(task)">
          <input v-model="task" type="text" />
          <input type="submit" value="ADD">
        </form>
        <article class="pa3 pa5-ns">
          <ul class="list pl0 ml0 center mw6 ba b--light-silver br2">
            <li v-for="todo of todos" class="flex items-center ph3 pv3 bb b--light-silver">
              <span v-bind:class="{strike: todo.complete}" class="flex-auto">{{todo.id}} {{todo.task}}</span>
              <button @click="toggle(todo)"><img src="https://icon.now.sh/check" alt="toggle"></button>
              <button @click="remove(todo)"><img src="https://icon.now.sh/trash" alt="delete"></button>
            </li>
          </ul>
        </article>
      </div>
    </template>
    
    <script>
      import { mapState, mapActions } from 'vuex'
      import {init} from './shared'
    
      export default {
        fetch: init,
        computed: {
          ...mapState({
            todos: (state) => state.todos
          })
        },
        data () {
          return {
            task: 'Some data'
          }
        },
        methods: {
          ...mapActions([
            'add',
            'remove',
            'toggle'
          ])
        }
      }
    </script>

    active.vue:

    <template>
      <div>
        <article class="pa3 pa5-ns">
          <ul class="list pl0 ml0 center mw6 ba b--light-silver br2">
            <li v-for="todo of todos" class="flex items-center ph3 pv3 bb b--light-silver">
              <span class="flex-auto">{{todo.id}} {{todo.task}}</span>
            </li>
          </ul>
        </article>
      </div>
    </template>
    
    <script>
      import { mapState } from 'vuex'
      import {init} from './shared'
    
      export default {
        fetch: init,
        computed: {
          ...mapState({
            todos: (state) => state.todos.filter(t => !t.complete)
          })
        }
      }
    </script>

    completed.vue:

    <template>
      <div>
        <article class="pa3 pa5-ns">
          <ul class="list pl0 ml0 center mw6 ba b--light-silver br2">
            <li v-for="todo of todos" class="flex items-center ph3 pv3 bb b--light-silver">
              <span class="flex-auto">{{todo.id}} {{todo.task}}</span>
            </li>
          </ul>
        </article>
      </div>
    </template>
    
    <script>
      import { mapState } from 'vuex'
      import {init} from './shared'
    
      export default {
        fetch: init,
        computed: {
          ...mapState({
            todos: (state) => state.todos.filter(t => t.complete)
          })
        }
      }
    </script>
  • 相关阅读:
    什么,你还不会Mysql主从复制???快来看
    MySQL二进制安装(版本:5.7.26)
    MySQL--备份恢复【Mysqdump+xtrabackup(XBK)】
    Mysql日志分析(错误日志,Binlog日志,慢日志),有惊喜哦
    Mysql多实例启动
    Zabbix服务自定义监控和模板
    Centos7安装Zabbix服务端、Zabbix客户端和Win客户端配置(源码编译安装)
    运维工作经验汇总---------高级运维工程师
    手误【删库】 == 跑路,不存在的 ——删瓦辛格
    python——map()函数
  • 原文地址:https://www.cnblogs.com/Answer1215/p/7236669.html
Copyright © 2020-2023  润新知