[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>
[Nuxt] Display Vuex Data Differently in Each Page of Nuxt and Vue.js的更多相关文章
- [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.j ...
- [Nuxt] Build a Vue.js Form then use Vuex Actions to Post to an API in Nuxt
The default behavior of submitting an HTML form is to reload the page. You can use the Vue.js @submi ...
- Tutorial: Importing and analyzing data from a Web Page using Power BI Desktop
In this tutorial, you will learn how to import a table of data from a Web page and create a report t ...
- Nuxt使用Vuex
Vuex 是一个专为 Vue.js 应用程序开发的状态管理模式.它采用集中式存储管理应用的所有组件的状态,并以相应的规则保证状态以一种可预测的方式发生变化. 基础知识这里不再重述,学习的话请自行到官网 ...
- [Vue] Preload Data using Promises with Vue.js and Nuxt.js
Nuxt.js allows you to return a Promise from your data function so that you can asynchronously resolv ...
- [转]How to display the data read in DataReceived event handler of serialport
本文转自:https://stackoverflow.com/questions/11590945/how-to-display-the-data-read-in-datareceived-event ...
- PatentTips - Cross-domain data transfer using deferred page remapping
BACKGROUND OF THE INVENTION The present invention relates to data transfer across domains, and more ...
- Consolidate data by using multiple page fields
Consolidate data by using multiple page fields https://support.office.com/en-us/article/Consolidate- ...
- [Nuxt] Update Vuex State with Mutations and MapMutations in Vue.js
You commit changes to state in Vuex using defined mutations. You can easily access these state mutat ...
随机推荐
- 8.AXIS1基础
转自:https://blog.csdn.net/chjttony/article/details/6209998 1.AXIS简介: Axis是Apache组织推出的SOAP引擎,Axis项目是Ap ...
- scrollwidth ,clientwidth ,offsetwidth 三者的区别
clientwidth:内容可视区域的宽度 offsetwidth:元素整体宽度 scrollwidth:实际内容的宽度
- PHP 7.1安装xhprof进行性能分析
安装扩展该 xhprof扩展版本是从 https://github.com/longxinH/xhprof 获取的(第三方的一个库,官方版本不支持php7) 下载并编译xhprof扩展在web的htm ...
- 【Codeforces Round #426 (Div. 2) A】The Useless Toy
[Link]:http://codeforces.com/contest/834/problem/A [Description] [Solution] 开个大小为4的常量字符数组; +n然后余4,-n ...
- 《Java设计模式》之桥接模式
Bridge模式的概念 Bridge 模式是构造型的设计模式之中的一个.Bridge模式基于类的最小设计原则,通过使用封装,聚合以及继承等行为来让不同的类承担不同的责任.它的主要特点是把抽象(abst ...
- 在Google Drive上建立免费静态站点
现今建立一个属于自己的站点已经是一件非常普遍和简单的事情了. 你能够选择买空间,买域名.你也能够使用免费空间.免费域名.你能够选择动态的php wordpress,joomla或者是静态的站点(如使用 ...
- python实现获取文件列表中每一个文件keyword
功能描写叙述: 获取某个路径下的全部文件,提取出每一个文件里出现频率最高的前300个字.保存在数据库其中. 前提.你须要配置好nltk #!/usr/bin/python #coding=utf-8 ...
- WINDOWS8.1企业版官方下载
这是评估版 WINDOWS8.1企业版官方下载源 https://www.itechtics.com/download-windows-8-1-enterprise-offline-installer ...
- Linux shell command学习笔记(二)
<cut> 作用:从输入文件或者命令的输出中析取出各种域 用法:cut –c{字符串范围} –d{字段间分割符} –f{字段索引编号} 举例: (1)查看在线用户:who | cut –c ...
- 洛谷——P1101 单词方阵
https://www.luogu.org/problem/show?pid=1101#sub 题目描述 给一nXn的字母方阵,内可能蕴含多个“yizhong”单词.单词在方阵中是沿着同一方向连续摆放 ...