learn vuex
This commit is contained in:
commit
620f3604bb
3
vuex_demo1/.browserslistrc
Normal file
3
vuex_demo1/.browserslistrc
Normal file
@ -0,0 +1,3 @@
|
||||
> 1%
|
||||
last 2 versions
|
||||
not dead
|
5
vuex_demo1/.editorconfig
Normal file
5
vuex_demo1/.editorconfig
Normal file
@ -0,0 +1,5 @@
|
||||
[*.{js,jsx,ts,tsx,vue}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
17
vuex_demo1/.eslintrc.js
Normal file
17
vuex_demo1/.eslintrc.js
Normal file
@ -0,0 +1,17 @@
|
||||
module.exports = {
|
||||
root: true,
|
||||
env: {
|
||||
node: true
|
||||
},
|
||||
extends: [
|
||||
'plugin:vue/essential',
|
||||
'@vue/standard'
|
||||
],
|
||||
parserOptions: {
|
||||
parser: '@babel/eslint-parser'
|
||||
},
|
||||
rules: {
|
||||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
|
||||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
|
||||
}
|
||||
}
|
23
vuex_demo1/.gitignore
vendored
Normal file
23
vuex_demo1/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/dist
|
||||
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
24
vuex_demo1/README.md
Normal file
24
vuex_demo1/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# vuex_demo1
|
||||
|
||||
## Project setup
|
||||
```
|
||||
npm install
|
||||
```
|
||||
|
||||
### Compiles and hot-reloads for development
|
||||
```
|
||||
npm run serve
|
||||
```
|
||||
|
||||
### Compiles and minifies for production
|
||||
```
|
||||
npm run build
|
||||
```
|
||||
|
||||
### Lints and fixes files
|
||||
```
|
||||
npm run lint
|
||||
```
|
||||
|
||||
### Customize configuration
|
||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
5
vuex_demo1/babel.config.js
Normal file
5
vuex_demo1/babel.config.js
Normal file
@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
'@vue/cli-plugin-babel/preset'
|
||||
]
|
||||
}
|
19
vuex_demo1/jsconfig.json
Normal file
19
vuex_demo1/jsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "esnext",
|
||||
"baseUrl": "./",
|
||||
"moduleResolution": "node",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
"lib": [
|
||||
"esnext",
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"scripthost"
|
||||
]
|
||||
}
|
||||
}
|
20239
vuex_demo1/package-lock.json
generated
Normal file
20239
vuex_demo1/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
30
vuex_demo1/package.json
Normal file
30
vuex_demo1/package.json
Normal file
@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "vuex_demo1",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build",
|
||||
"lint": "vue-cli-service lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"core-js": "^3.8.3",
|
||||
"vue": "^2.6.14",
|
||||
"vuex": "^3.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.12.16",
|
||||
"@babel/eslint-parser": "^7.12.16",
|
||||
"@vue/cli-plugin-babel": "~5.0.0",
|
||||
"@vue/cli-plugin-eslint": "~5.0.0",
|
||||
"@vue/cli-plugin-vuex": "~5.0.0",
|
||||
"@vue/cli-service": "~5.0.0",
|
||||
"@vue/eslint-config-standard": "^6.1.0",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-plugin-import": "^2.25.3",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"eslint-plugin-promise": "^5.1.0",
|
||||
"eslint-plugin-vue": "^8.0.3",
|
||||
"vue-template-compiler": "^2.6.14"
|
||||
}
|
||||
}
|
BIN
vuex_demo1/public/favicon.ico
Normal file
BIN
vuex_demo1/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
17
vuex_demo1/public/index.html
Normal file
17
vuex_demo1/public/index.html
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
</html>
|
28
vuex_demo1/src/App.vue
Normal file
28
vuex_demo1/src/App.vue
Normal file
@ -0,0 +1,28 @@
|
||||
<template>
|
||||
<div>
|
||||
<my-add></my-add>
|
||||
<p>-----------------------------------------</p>
|
||||
<my-sub></my-sub>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import add from './components/add.vue'
|
||||
import sub from "./components/sub.vue"
|
||||
|
||||
export default {
|
||||
components:{
|
||||
"my-add":add,
|
||||
"my-sub":sub
|
||||
},
|
||||
data(){
|
||||
return{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
BIN
vuex_demo1/src/assets/logo.png
Normal file
BIN
vuex_demo1/src/assets/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
32
vuex_demo1/src/components/add.vue
Normal file
32
vuex_demo1/src/components/add.vue
Normal file
@ -0,0 +1,32 @@
|
||||
<template>
|
||||
<div>
|
||||
<h3>当前最新的count值为:{{$store.state.count}}</h3>
|
||||
<button @click="addcount">+1</button>
|
||||
<button @click="btnhandle">+1 Async</button>
|
||||
<button @click="btnhandle1">+5 Async</button>
|
||||
<h3>{{$store.getters.showNum}}</h3>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
addcount(){
|
||||
this.$store.commit('add')
|
||||
},
|
||||
//异步让count自增1
|
||||
btnhandle(){
|
||||
//dispatch函数专门用来触发action
|
||||
this.$store.dispatch('addAsync')
|
||||
},
|
||||
btnhandle1(){
|
||||
this.$store.dispatch('addNAsync',5)
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
26
vuex_demo1/src/components/sub.vue
Normal file
26
vuex_demo1/src/components/sub.vue
Normal file
@ -0,0 +1,26 @@
|
||||
<template>
|
||||
<div>
|
||||
<h3>当前最新的count值为:{{count}}</h3>
|
||||
<button @click="subN(2)">-2</button>
|
||||
<button @click="xc(10)">*10</button>
|
||||
<button @click="subNAsync(10)">-10 Async</button>
|
||||
<h3>{{showNum1}}</h3>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { mapState,mapMutations,mapActions,mapGetters } from "vuex";
|
||||
export default {
|
||||
data(){
|
||||
return{ }
|
||||
},
|
||||
methods:{
|
||||
...mapMutations(['subN','xc']),
|
||||
...mapActions(['subNAsync']),
|
||||
},
|
||||
computed:{
|
||||
...mapState(['count']),
|
||||
...mapGetters(['showNum','showNum1'])
|
||||
}
|
||||
}
|
||||
</script>
|
10
vuex_demo1/src/main.js
Normal file
10
vuex_demo1/src/main.js
Normal file
@ -0,0 +1,10 @@
|
||||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
import store from './store'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
new Vue({
|
||||
store,
|
||||
render: h => h(App)
|
||||
}).$mount('#app')
|
58
vuex_demo1/src/store/index.js
Normal file
58
vuex_demo1/src/store/index.js
Normal file
@ -0,0 +1,58 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
export default new Vuex.Store({
|
||||
state: {
|
||||
//存放全局共享数据
|
||||
count:0
|
||||
},
|
||||
getters: {
|
||||
showNum(state){
|
||||
let newcount = state.count *2
|
||||
return '测试getters,更新的数量为count*2: '+ newcount
|
||||
},
|
||||
showNum1(state){
|
||||
let newcount = state.count *3
|
||||
return '测试getters,更新的数量为为count*3: '+ newcount
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
//变更store中的数据
|
||||
add(state){
|
||||
state.count++
|
||||
},
|
||||
addN(state,step){
|
||||
state.count+=step
|
||||
},
|
||||
sub(state){
|
||||
state.count--
|
||||
},
|
||||
subN(state,step){
|
||||
state.count-=step
|
||||
},
|
||||
xc(state,step){
|
||||
state.count=state.count * step
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
addAsync(context){
|
||||
setTimeout(()=>{
|
||||
context.commit('add')
|
||||
},1000)
|
||||
},
|
||||
addNAsync(context,step){
|
||||
setTimeout(()=>{
|
||||
context.commit('addN',step)
|
||||
},1000)
|
||||
},
|
||||
subNAsync(context,step){
|
||||
setTimeout(()=>{
|
||||
context.commit('subN',step)
|
||||
},1000)
|
||||
}
|
||||
},
|
||||
modules: {
|
||||
}
|
||||
})
|
5
vuex_demo1/vue.config.js
Normal file
5
vuex_demo1/vue.config.js
Normal file
@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@vue/cli-service')
|
||||
module.exports = defineConfig({
|
||||
transpileDependencies: true,
|
||||
lintOnSave: false,
|
||||
})
|
3
vuex_demo2/.browserslistrc
Normal file
3
vuex_demo2/.browserslistrc
Normal file
@ -0,0 +1,3 @@
|
||||
> 1%
|
||||
last 2 versions
|
||||
not dead
|
23
vuex_demo2/.gitignore
vendored
Normal file
23
vuex_demo2/.gitignore
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
.DS_Store
|
||||
node_modules
|
||||
/dist
|
||||
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Log files
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
.vscode
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
19
vuex_demo2/README.md
Normal file
19
vuex_demo2/README.md
Normal file
@ -0,0 +1,19 @@
|
||||
# vuex_demo2
|
||||
|
||||
## Project setup
|
||||
```
|
||||
yarn install
|
||||
```
|
||||
|
||||
### Compiles and hot-reloads for development
|
||||
```
|
||||
yarn serve
|
||||
```
|
||||
|
||||
### Compiles and minifies for production
|
||||
```
|
||||
yarn build
|
||||
```
|
||||
|
||||
### Customize configuration
|
||||
See [Configuration Reference](https://cli.vuejs.org/config/).
|
5
vuex_demo2/babel.config.js
Normal file
5
vuex_demo2/babel.config.js
Normal file
@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
presets: [
|
||||
'@vue/cli-plugin-babel/preset'
|
||||
]
|
||||
}
|
19
vuex_demo2/jsconfig.json
Normal file
19
vuex_demo2/jsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es5",
|
||||
"module": "esnext",
|
||||
"baseUrl": "./",
|
||||
"moduleResolution": "node",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"src/*"
|
||||
]
|
||||
},
|
||||
"lib": [
|
||||
"esnext",
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"scripthost"
|
||||
]
|
||||
}
|
||||
}
|
18113
vuex_demo2/package-lock.json
generated
Normal file
18113
vuex_demo2/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
22
vuex_demo2/package.json
Normal file
22
vuex_demo2/package.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "vuex_demo2",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"serve": "vue-cli-service serve",
|
||||
"build": "vue-cli-service build"
|
||||
},
|
||||
"dependencies": {
|
||||
"ant-design-vue": "^1.7.8",
|
||||
"axios": "^0.27.2",
|
||||
"core-js": "^3.8.3",
|
||||
"vue": "^2.6.14",
|
||||
"vuex": "^3.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "~5.0.0",
|
||||
"@vue/cli-plugin-vuex": "~5.0.0",
|
||||
"@vue/cli-service": "~5.0.0",
|
||||
"vue-template-compiler": "^2.6.14"
|
||||
}
|
||||
}
|
BIN
vuex_demo2/public/favicon.ico
Normal file
BIN
vuex_demo2/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
17
vuex_demo2/public/index.html
Normal file
17
vuex_demo2/public/index.html
Normal file
@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
||||
</noscript>
|
||||
<div id="app"></div>
|
||||
<!-- built files will be auto injected -->
|
||||
</body>
|
||||
</html>
|
27
vuex_demo2/public/list.json
Normal file
27
vuex_demo2/public/list.json
Normal file
@ -0,0 +1,27 @@
|
||||
[
|
||||
{
|
||||
"id": 0,
|
||||
"info": "Racing car sprays burning fuel into crowd.",
|
||||
"done": false
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"info": " Japanese princess to wed commoner.",
|
||||
"done": true
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"info": "Australian walks 100km after outback crash.",
|
||||
"done": false
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"info": "Man charged over missing wedding girl.",
|
||||
"done": true
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
"info": "Los Angeles battles huge wildfires.",
|
||||
"done": false
|
||||
}
|
||||
]
|
99
vuex_demo2/src/App.vue
Normal file
99
vuex_demo2/src/App.vue
Normal file
@ -0,0 +1,99 @@
|
||||
<template>
|
||||
<div id="app">
|
||||
<a-input placeholder="请输入任务" class="my_ipt" :value="inputValue" @change="handleInputChange"/>
|
||||
<a-button type="primary" @click="addItemToList">添加事项</a-button>
|
||||
|
||||
<a-list bordered :dataSource="infolist" class="dt_list">
|
||||
<a-list-item slot="renderItem" slot-scope="item">
|
||||
<!-- 复选框 -->
|
||||
<a-checkbox :checked="item.done" @change="(e)=>(cbStatusChange(e,item.id))">{{ item.info }}</a-checkbox>
|
||||
<!-- 删除链接 -->
|
||||
<a slot="actions" @click="removeItemByID(item.id)">删除</a>
|
||||
</a-list-item>
|
||||
|
||||
<!-- footer区域 -->
|
||||
<div class="footer" slot="footer">
|
||||
<span>{{unDoneLength}}条剩余</span>
|
||||
<a-button-group>
|
||||
<a-button :type="viewstatus==='all'?'primary':'default'" @click="changelist('all')">全部</a-button>
|
||||
<a-button :type="viewstatus==='undone'?'primary':'default'" @click="changelist('undone')">未完成</a-button>
|
||||
<a-button :type="viewstatus==='done'?'primary':'default'" @click="changelist('done')">已完成</a-button>
|
||||
</a-button-group>
|
||||
<a @click="clean">清除已完成</a>
|
||||
</div>
|
||||
</a-list>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {mapState,mapGetters} from 'vuex';
|
||||
export default {
|
||||
name: "app",
|
||||
data() {
|
||||
return { };
|
||||
},
|
||||
created(){
|
||||
this.$store.dispatch('getlist')
|
||||
},
|
||||
methods: {
|
||||
handleInputChange(e){
|
||||
// console.log(e.target.value)
|
||||
this.$store.commit('setInputValue',e.target.value)
|
||||
},
|
||||
addItemToList(){
|
||||
//trim()去除字符串头尾两边的空格
|
||||
if(this.inputValue.trim().length <=0){
|
||||
//弹出一个警告框
|
||||
return this.$message.warning('文本框内容不能为空')
|
||||
}
|
||||
this.$store.commit('addItem')
|
||||
},
|
||||
removeItemByID(id){
|
||||
// console.log(id)
|
||||
this.$store.commit("removeItem",id)
|
||||
},
|
||||
cbStatusChange(e,id){
|
||||
//监听复选框选中状态的变化
|
||||
// console.log(e.target.checked,id)
|
||||
const param = {
|
||||
id:id,
|
||||
done:e.target.checked
|
||||
}
|
||||
this.$store.commit('changeStatus',param)
|
||||
},
|
||||
//清除已完成的任务
|
||||
clean(){
|
||||
this.$store.commit('cleanDone')
|
||||
},
|
||||
//修改页面展示的列表数据
|
||||
changelist(status){
|
||||
// console.log(status)
|
||||
this.$store.commit('changeviewstatus',status)
|
||||
}
|
||||
},
|
||||
computed:{
|
||||
...mapState(['list','inputValue','viewstatus']),
|
||||
...mapGetters(['unDoneLength','infolist'])
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
#app {
|
||||
margin: 175px 450px;
|
||||
padding: 10px;
|
||||
}
|
||||
.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>
|
BIN
vuex_demo2/src/assets/logo.png
Normal file
BIN
vuex_demo2/src/assets/logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
17
vuex_demo2/src/main.js
Normal file
17
vuex_demo2/src/main.js
Normal file
@ -0,0 +1,17 @@
|
||||
import Vue from 'vue'
|
||||
import App from './App.vue'
|
||||
import store from './store'
|
||||
//1、导入ant-design-vue 组件库
|
||||
import Antd from 'ant-design-vue'
|
||||
|
||||
//2、导入组件库的样式表
|
||||
import 'ant-design-vue/dist/antd.css'
|
||||
|
||||
Vue.config.productionTip = false
|
||||
|
||||
Vue.use(Antd)
|
||||
|
||||
new Vue({
|
||||
store,
|
||||
render: h => h(App)
|
||||
}).$mount('#app')
|
90
vuex_demo2/src/store/index.js
Normal file
90
vuex_demo2/src/store/index.js
Normal file
@ -0,0 +1,90 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
import axios from 'axios';
|
||||
|
||||
Vue.use(Vuex)
|
||||
|
||||
export default new Vuex.Store({
|
||||
state: {
|
||||
//所有的任务列表
|
||||
list:[],
|
||||
inputValue:'aaa',
|
||||
nextID:5,
|
||||
viewstatus:'all'
|
||||
},
|
||||
getters: {
|
||||
//统计未完成条数的情况
|
||||
unDoneLength(state){
|
||||
return state.list.filter(v=>v.done === false).length
|
||||
},
|
||||
infolist(state){
|
||||
if(state.viewstatus === 'all'){
|
||||
return state.list
|
||||
}
|
||||
if(state.viewstatus === 'undone'){
|
||||
return state.list.filter(v=>!v.done)
|
||||
}
|
||||
if(state.viewstatus === 'done'){
|
||||
return state.list.filter(v=>v.done)
|
||||
}
|
||||
return state.list
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
initlist(state,list){
|
||||
//接收到action中getlist函数传过来额参数后,对state中的list直接进行赋值操作
|
||||
state.list = list
|
||||
},
|
||||
setInputValue(state,value){
|
||||
//为store中的InputValue赋值
|
||||
state.inputValue = value
|
||||
},
|
||||
addItem(state){
|
||||
//添加列表项
|
||||
const obj = {
|
||||
id:state.nextID,
|
||||
info:state.inputValue.trim(),
|
||||
done:false
|
||||
}
|
||||
state.list.push(obj)
|
||||
state.nextID++
|
||||
state.inputValue = ''
|
||||
},
|
||||
removeItem(state,id){
|
||||
//删除列表项
|
||||
//根据id查找对应项的索引
|
||||
const removeId = state.list.findIndex(v=>v.id === id)
|
||||
if(removeId !== -1){
|
||||
state.list.splice(removeId,1)
|
||||
}
|
||||
},
|
||||
changeStatus(state,param){
|
||||
//修改列表项的选中状态
|
||||
const updateId = state.list.findIndex(v=>v.id === param.id)
|
||||
if(updateId !== -1){
|
||||
state.list[updateId].done = param.done
|
||||
}
|
||||
},
|
||||
//清除已完成的任务
|
||||
cleanDone(state){
|
||||
state.list = state.list.filter(v=>v.done === false)
|
||||
},
|
||||
//修改视图中的关键字
|
||||
changeviewstatus(state,status){
|
||||
state.viewstatus = status
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
getlist(context){
|
||||
//发送请求请求list.json中的数据
|
||||
axios.get('/list.json')
|
||||
.then(res=>{
|
||||
console.log(res.data)
|
||||
//调用imutation中的initlist函数,并将res.date传给它
|
||||
context.commit('initlist',res.data)
|
||||
})
|
||||
}
|
||||
},
|
||||
modules: {
|
||||
}
|
||||
})
|
4
vuex_demo2/vue.config.js
Normal file
4
vuex_demo2/vue.config.js
Normal file
@ -0,0 +1,4 @@
|
||||
const { defineConfig } = require('@vue/cli-service')
|
||||
module.exports = defineConfig({
|
||||
transpileDependencies: true
|
||||
})
|
5819
vuex_demo2/yarn.lock
Normal file
5819
vuex_demo2/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user