欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vuex實(shí)現(xiàn)記事本功能

 更新時(shí)間:2022年05月22日 08:37:03   作者:£白晝の星☆  
這篇文章主要為大家詳細(xì)介紹了Vuex實(shí)現(xiàn)記事本功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Vuex實(shí)現(xiàn)記事本功能的具體代碼,供大家參考,具體內(nèi)容如下

首先:執(zhí)行命令 安裝Vuex

npm install vuex@next --save

在mian.js 中掛在vuex

import store from './store'
?
new Vue({
? store,
? render: h => h(App)
}).$mount('#app')

這里使用的 Ant Design UI :

npm install ant-design-vue --save

在 main.js 中完整引入

import Antd from 'ant-design-vue'
import 'ant-design-vue/dist/antd.css'
Vue.use(Antd)

App.vue中

<template>
? <div id="app">
? ? <div>
? ? ? <a-input placeholder="請(qǐng)輸入任務(wù)" class="my_ipt" :value='inputVal'
? ? ? @change="handleInputChange"
? ? ? />
? ? ? <a-button type="primary" @click="addItem">添加事項(xiàng)</a-button>
?
? ? ? <a-list bordered :dataSource="infoList" class="dt_list">
? ? ? ? <a-list-item slot="renderItem" slot-scope="item">
? ? ? ? ? <!-- 復(fù)選框 -->
? ? ? ? ? <a-checkbox :checked='item.done' @change="changeItem(item.id,$event.target.checked)">{{ item.info }}</a-checkbox>
? ? ? ? ? <!-- 刪除鏈接 -->
? ? ? ? ? <a slot="actions" @click="deleteItemById(item.id)">刪除</a>
? ? ? ? </a-list-item>
?
? ? ? ? <!-- footer區(qū)域 -->
? ? ? ? <div class="footer" slot="footer">
? ? ? ? ? <span>{{unDoneNub}}條未完成</span>
? ? ? ? ? <a-button-group>
? ? ? ? ? ? <a-button :type="ViewType=='all'?'primary':''" @click="changeList('all')">全部</a-button>
? ? ? ? ? ? <a-button :type="ViewType=='undone'?'primary':''" @click="changeList('undone')">未完成</a-button>
? ? ? ? ? ? <a-button :type="ViewType=='done'?'primary':''" @click="changeList('done')">已完成</a-button>
? ? ? ? ? </a-button-group>
? ? ? ? ? <a @click="deleteDone">清除已完成</a>
? ? ? ? </div>
? ? ? </a-list>
? ? </div>
? </div>
</template>
<script>
import { mapState, mapGetters } from 'vuex'
export default {
? name: 'app',
? data () {
? ? return {
? ? ? // 模擬數(shù)據(jù)
? ? ? // list: []
? ? }
? },
? computed: {
? ? ...mapState(['list', 'inputVal', 'ViewType']),
? ? ...mapGetters(['unDoneNub', 'infoList'])
? },
? created () {
? ? this.$store.dispatch('getList')
? },
? methods: {
? ? handleInputChange (e) {
? ? ? console.log(e.target.value)
? ? ? // 拿到輸入框的值 ?保存到vuex中
? ? ? this.$store.commit('setInputVal', e.target.value)
? ? },
? ? // 向列表中添加事項(xiàng)
? ? addItem () {
? ? ? if (this.inputVal.trim().length <= 0) {
? ? ? ? return alert('文本框不能為空')
? ? ? }
? ? ? // 向store中調(diào)用函數(shù) ?來(lái)修改數(shù)據(jù) ?不可以直接修改
? ? ? this.$store.commit('addItem')
? ? },
?
? ? // 刪除
? ? deleteItemById (id) {
? ? ? // console.log(id);
? ? ? this.$store.commit('deleteItem', id)
? ? },
?
? ? // 改變狀態(tài)
? ? changeItem (id, e) {
? ? ? console.log(id, e)
? ? ? // 通過(guò)id改變狀態(tài)
? ? ? this.$store.commit('changeItem', id)
? ? },
?
? ? // 清除已完成
? ? deleteDone () {
? ? ? this.$store.commit('deleteDone')
? ? },
?
? ? changeList (type) {
? ? ? this.$store.commit('changeList', type)
? ? }
?
? }
}
</script>
<style scoped>
#app {
? padding: 10px;
? margin: 0 auto;
? display: flex;
? justify-content: center;
}
.my_ipt {
? width: 500px;
? margin-right: 10px;
}
.dt_list {
? width: 500px;
? margin-top: 10px;
}
.footer {
? display: flex;
? justify-content: space-between;
? align-items: center;
}
</style>

store index.js 中

import Vue from 'vue'
import Vuex from 'vuex'
import axios from 'axios'
?
Vue.use(Vuex)
?
export default new Vuex.Store({
? state: {
? ? list: [],
? ? inputVal: '',
? ? id: 10,
? ? ViewType: 'all'
? },
? // 真正操作數(shù)據(jù)的地方
? mutations: {
? ? INITLIST (state, data) {
? ? ? state.list = data
? ? },
? ? setInputVal (state, data) {
? ? ? state.inputVal = data
? ? },
? ? addItem (state) {
? ? ? const obj = {
? ? ? ? id: state.id,
? ? ? ? info: state.inputVal.trim(),
? ? ? ? done: false
? ? ? }
? ? ? state.list.push(obj)
? ? ? state.id++
? ? ? state.inputVal = ''
? ? },
? ? // 刪除已完成
? ? deleteDone (state) {
? ? ? state.list = state.list.filter(item => {
? ? ? ? return item.done != true
? ? ? })
? ? },
? ? deleteItem (state, id) {
? ? ? state.list = state.list.filter(item => {
? ? ? ? // console.log(item.id);
? ? ? ? return item.id != id
? ? ? })
? ? },
? ? // 改狀態(tài)
? ? changeItem (state, id) {
? ? ? // 對(duì)應(yīng)id的done值取反 先拿索引 根據(jù)索引 取反對(duì)應(yīng)的狀態(tài) ?如果有多重狀態(tài) 則需要參數(shù)傳遞
? ? ? const index = state.list.findIndex(item => {
? ? ? ? return item.id === id
? ? ? })
? ? ? if (index !== -1) {
? ? ? ? state.list[index].done = !state.list[index].done
? ? ? }
? ? },
? ? // 改變列表
? ? changeList (state, type) {
? ? ? state.ViewType = type
? ? ? state
? ? }
? },
? actions: {
? ? //模仿發(fā)送請(qǐng)求
? ? getList (content) {
? ? ? axios.get('./list.json').then(res => {
? ? ? ? console.log(res.data)
? ? ? ? content.commit('INITLIST', res.data)
? ? ? })
? ? }
?
? },
? modules: {
? },
? getters: {
? ? // 未完成的數(shù)量
? ? unDoneNub (state) {
? ? ? return (state.list.filter(item => {
? ? ? ? return item.done == false
? ? ? })).length
? ? },
? ? // 根據(jù)列表類型 過(guò)濾不同的展示列表
? ? infoList (state) {
? ? ? if (state.ViewType == 'all') {
? ? ? ? return state.list
? ? ? }
? ? ? if (state.ViewType == 'undone') {
? ? ? ? return state.list.filter(item => !item.done)
? ? ? }
? ? ? if (state.ViewType == 'done') {
? ? ? ? return state.list.filter(item => item.done)
? ? ? }
? ? }
? }
})

list.json

[
? ? {
? ? ? ? "id": 0,
? ? ? ? "info": "打籃球",
? ? ? ? "done": false
? ? },
? ? {
? ? ? ? "id": 1,
? ? ? ? "info": "打王者榮耀",
? ? ? ? "done": true
? ? },
? ? {
? ? ? ? "id": 2,
? ? ? ? "info": "學(xué)習(xí)",
? ? ? ? "done": false
? ? },
? ? {
? ? ? ? "id": 3,
? ? ? ? "info": "吃飯",
? ? ? ? "done": false
? ? },
? ? {
? ? ? ? "id": 4,
? ? ? ? "info": "睡覺(jué)",
? ? ? ? "done": false
? ? }
]

結(jié)果圖:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Vue中的默認(rèn)插槽詳解

    Vue中的默認(rèn)插槽詳解

    在 Vue 中,插槽(Slot)是一種非常強(qiáng)大且靈活的機(jī)制,用于在組件中插入內(nèi)容,默認(rèn)插槽是在父組件中傳遞內(nèi)容給子組件時(shí)使用的一種方式,這篇文章主要介紹了Vue中的默認(rèn)插槽詳解,需要的朋友可以參考下
    2024-01-01
  • Vue3中的setup語(yǔ)法糖、computed函數(shù)、watch函數(shù)詳解

    Vue3中的setup語(yǔ)法糖、computed函數(shù)、watch函數(shù)詳解

    這篇文章主要介紹了Vue3中的setup語(yǔ)法糖、computed函數(shù)、watch函數(shù),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03
  • vuejs實(shí)現(xiàn)下拉框菜單選擇

    vuejs實(shí)現(xiàn)下拉框菜單選擇

    這篇文章主要為大家詳細(xì)介紹了vuejs實(shí)現(xiàn)下拉框菜單選擇,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-10-10
  • 在Vue中實(shí)現(xiàn)地圖熱點(diǎn)展示與交互的方法詳解(如熱力圖)

    在Vue中實(shí)現(xiàn)地圖熱點(diǎn)展示與交互的方法詳解(如熱力圖)

    隨著大數(shù)據(jù)和可視化技術(shù)的發(fā)展,地圖熱點(diǎn)展示越來(lái)越受到人們的關(guān)注,在Vue應(yīng)用中,我們通常需要實(shí)現(xiàn)地圖熱點(diǎn)的展示和交互,以便更好地呈現(xiàn)數(shù)據(jù)和分析結(jié)果,本文將介紹在Vue中如何進(jìn)行地圖熱點(diǎn)展示與交互,包括熱力圖、點(diǎn)聚合等
    2023-07-07
  • vue中過(guò)濾器的用法

    vue中過(guò)濾器的用法

    這篇文章介紹了vue中過(guò)濾器的用法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-03-03
  • 為什么Vue3.0使用Proxy實(shí)現(xiàn)數(shù)據(jù)監(jiān)聽(tīng)(defineProperty表示不背這個(gè)鍋)

    為什么Vue3.0使用Proxy實(shí)現(xiàn)數(shù)據(jù)監(jiān)聽(tīng)(defineProperty表示不背這個(gè)鍋)

    這篇文章主要介紹了為什么Vue3.0使用Proxy實(shí)現(xiàn)數(shù)據(jù)監(jiān)聽(tīng)?defineProperty表示不背這個(gè)鍋,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-10-10
  • vue使用nprogress實(shí)現(xiàn)進(jìn)度條

    vue使用nprogress實(shí)現(xiàn)進(jìn)度條

    這篇文章主要為大家詳細(xì)介紹了vue使用nprogress實(shí)現(xiàn)進(jìn)度條,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • vue-router路由傳參及隱藏參數(shù)問(wèn)題

    vue-router路由傳參及隱藏參數(shù)問(wèn)題

    這篇文章主要介紹了vue-router路由傳參及隱藏參數(shù)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-12-12
  • 解決vue 給window添加和移除resize事件遇到的坑

    解決vue 給window添加和移除resize事件遇到的坑

    這篇文章主要介紹了解決vue 給window添加和移除resize事件遇到的坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-07-07
  • Vue如何更改表格中的某一行選項(xiàng)值

    Vue如何更改表格中的某一行選項(xiàng)值

    這篇文章主要介紹了Vue如何更改表格中的某一行選項(xiàng)值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-04-04

最新評(píng)論