[Nuxt] Add Arrays of Data to the Vuex Store and Display Them in Vue.js Templates
2023-09-14 09:00:51 时间
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>
相关文章
- Java项目毕业设计:基于springboot+vue的电影视频网站系统「建议收藏」
- js书写原生ajax,JS 原生ajax写法
- js面试题及答案2020_JS面试题大全
- [Vue] v-model 绑定对象不实时更新
- Vue之Vuex(一)
- 【第一篇】Vue的初次邂逅
- JS之在Vue对象内部获取vue对象的索引(箭头函数的闭包导致this代表的是函数本身)「建议收藏」
- Vue生命周期
- Vue中组件通信
- Vue中class与style绑定
- Vue的基本模板
- Vue | 使用 SVG sprite loader 来引入 svg
- Vue项目中的mock.js的使用以及基本用法和ES6的新增方法
- vue md5.js_VUE.js
- vue中map用法_vue里面的meta用法
- 一面高频vue面试题
- 合格vue开发者应该知道的面试题
- vue.js单页应用_vue嵌入第三方页面
- 在网页文档中引入Vue.js的方法有哪些?_vue直接引入js文件没有用
- vue如何引用js文件_html转化为vue组件
- VUE组件封装_vue使用组件
- Vue上传文件遇到的问题[通俗易懂]
- js 数组去除重复数据-当WPS开始像支持VBA一样支持JS语言时,微软又该何去何从?
- 前端二面vue面试题(边面边更)1
- vue.js客服系统实时聊天项目开发(四)引入iconfont图标代码
- Vue 全家桶介绍
- 用Vue.js开发企业管理后台,我做到了
- JS将所有对象s的属性复制给对象r(原生js+jquery)