Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CSDN 技术社区
skill_tree_vue
提交
1a0e80b5
S
skill_tree_vue
项目概览
CSDN 技术社区
/
skill_tree_vue
通知
5
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
skill_tree_vue
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
1a0e80b5
编写于
4月 22, 2022
作者:
Z
zhaoss
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
2.3.3小节习题、关键字添加
上级
49e34218
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
241 addition
and
8 deletion
+241
-8
data/2.Vue中阶/3.VueX状态管理/1.VueX是什么?/exercises.json
data/2.Vue中阶/3.VueX状态管理/1.VueX是什么?/exercises.json
+1
-1
data/2.Vue中阶/3.VueX状态管理/2.Vuex的安装与配置/exercises.json
data/2.Vue中阶/3.VueX状态管理/2.Vuex的安装与配置/exercises.json
+1
-1
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/config.json
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/config.json
+16
-0
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/exercises.json
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/exercises.json
+8
-0
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/exercises.md
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/exercises.md
+194
-0
data/2.Vue中阶/4.Vue-cli/1.vue-cli脚手架安装/config.json
data/2.Vue中阶/4.Vue-cli/1.vue-cli脚手架安装/config.json
+4
-1
data/2.Vue中阶/4.Vue-cli/2.通过脚手架构建项目/config.json
data/2.Vue中阶/4.Vue-cli/2.通过脚手架构建项目/config.json
+4
-1
data/2.Vue中阶/4.Vue-cli/3.vue-cli服务命令/config.json
data/2.Vue中阶/4.Vue-cli/3.vue-cli服务命令/config.json
+4
-1
data/2.Vue中阶/4.Vue-cli/4.vue.config.js的配置/config.json
data/2.Vue中阶/4.Vue-cli/4.vue.config.js的配置/config.json
+4
-1
data/2.Vue中阶/4.Vue-cli/5.ESLint语法规则插件配置/config.json
data/2.Vue中阶/4.Vue-cli/5.ESLint语法规则插件配置/config.json
+4
-1
data/tree.json
data/tree.json
+1
-1
未找到文件。
data/2.Vue中阶/3.VueX状态管理/1.VueX是什么?/exercises.json
浏览文件 @
1a0e80b5
{
"type"
:
"code_options"
,
"author"
:
null
,
"author"
:
"zhaoss"
,
"source"
:
"exercises.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"db244175d01241fbbaa1faab01934943"
...
...
data/2.Vue中阶/3.VueX状态管理/2.Vuex的安装与配置/exercises.json
浏览文件 @
1a0e80b5
{
"type"
:
"code_options"
,
"author"
:
null
,
"author"
:
"zhaoss"
,
"source"
:
"exercises.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"55859253e09246f5a267f5cf262d2dd0"
...
...
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/config.json
0 → 100644
浏览文件 @
1a0e80b5
{
"node_id"
:
"vue-6f4473024d73448bb01674d9d17bdeac"
,
"keywords"
:
[
"VueX核心内容"
,
"VueX核心"
],
"children"
:
[],
"export"
:
[
"exercises.json"
],
"keywords_must"
:
[
"VueX"
],
"keywords_forbid"
:
[]
}
\ No newline at end of file
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/exercises.json
0 → 100644
浏览文件 @
1a0e80b5
{
"type"
:
"code_options"
,
"author"
:
null
,
"source"
:
"exercises.md"
,
"notebook_enable"
:
false
,
"exercise_id"
:
"307cb2afb9e048b8a42f20ea5df05840"
}
\ No newline at end of file
data/2.Vue中阶/3.VueX状态管理/3.VueX的核心内容/exercises.md
0 → 100644
浏览文件 @
1a0e80b5
# VueX核心内容
<div
style=
"color: pink;"
>
小常识:
</div>
<br>
**State**
State提供唯一的公共数据源,所有共享的数据都要统一放到Store中的State中存储
**在组件中访问State的方式:**
```
javascript
1
).
this
.
$store
.
state
.
全局数据名称
如
:
this
.
$store
.
state
.
count
2
).
先按需导入mapState函数
:
import
{
mapState
}
from
'
vuex
'
然后数据映射为计算属性
:
computed
:{
...
mapState
([
'
全局数据名称
'
])
}
```
**Mutation**
Mutation用于修改变更$store中的数据
**使用方式第一种**
打开store.js文件,在mutations中添加代码如下
```
javascript
mutations
:
{
add
(
state
,
step
){
//第一个形参永远都是state也就是$state对象
//第二个形参是调用add时传递的参数
state
.
count
+=
step
;
}
}
```
然后在Addition.vue中给按钮添加事件代码如下:
```
javascript
<
button
@
click
=
"
Add
"
>+
1
<
/button
>
methods
:{
Add
(){
//使用commit函数调用mutations中的对应函数,
//第一个参数就是我们要调用的mutations中的函数名
//第二个参数就是传递给add函数的参数
this
.
$store
.
commit
(
'
add
'
,
10
)
}
}
```
**使用mutations的第二种方式:**
```
javascript
import
{
mapMutations
}
from
'
vuex
'
methods
:{
...
mapMutations
([
'
add
'
])
}
```
```
javascript
import
{
mapState
,
mapMutations
}
from
'
vuex
'
export
default
{
data
()
{
return
{}
},
methods
:{
//获得mapMutations映射的sub函数
...
mapMutations
([
'
sub
'
]),
//当点击按钮时触发Sub函数
Sub
(){
//调用sub函数完成对数据的操作
this
.
sub
(
10
);
}
},
computed
:{
...
mapState
([
'
count
'
])
}
}
```
**Action**
在mutations中不能编写异步的代码,会导致vue调试器的显示出错。
在vuex中我们可以使用Action来执行异步操作。
**操作步骤第一种**
打开store.js文件,修改Action,如下:
```
javascript
actions
:
{
addAsync
(
context
,
step
){
setTimeout
(()
=>
{
context
.
commit
(
'
add
'
,
step
);
},
2000
)
}
}
```
然后在Addition.vue中给按钮添加事件代码如下
```
javascript
<
button
@
click
=
"
AddAsync
"
>
...
+
1
<
/button
>
methods
:{
AddAsync
(){
this
.
$store
.
dispatch
(
'
addAsync
'
,
5
)
}
}
```
**操作步骤第二种**
```
javascript
import
{
mapActions
}
from
'
vuex
'
methods
:{
...
mapMutations
([
'
subAsync
'
])
}
```
```
javascript
import
{
mapState
,
mapMutations
,
mapActions
}
from
'
vuex
'
export
default
{
data
()
{
return
{}
},
methods
:{
//获得mapMutations映射的sub函数
...
mapMutations
([
'
sub
'
]),
//当点击按钮时触发Sub函数
Sub
(){
//调用sub函数完成对数据的操作
this
.
sub
(
10
);
},
//获得mapActions映射的addAsync函数
...
mapActions
([
'
subAsync
'
]),
asyncSub
(){
this
.
subAsync
(
5
);
}
},
computed
:{
...
mapState
([
'
count
'
])
}
}
```
**Getter**
Getter用于对Store中的数据进行加工处理形成新的数据
它只会包装Store中保存的数据,并不会修改Store中保存的数据,当Store中的数据发生变化时,Getter生成的内容也会随之变化
**使用**
打开store.js文件,添加getters,然后打开Addition.vue中,添加插值表达式使用getters
```
javascript
export
default
new
Vuex
.
Store
({
.......
getters
:{
//添加了一个showNum的属性
showNum
:
state
=>
{
return
'
最新的count值为:
'
+
state
.
count
;
}
}
})
```
或者也可以在Addition.vue中,导入mapGetters,并将之映射为计算属性
```
javascript
import
{
mapGetters
}
from
'
vuex
'
computed
:{
...
mapGetters
([
'
showNum
'
])
}
<
br
>
<
div
style
=
"
color: pink;
"
>
小测试
:
<
/div
>
根据上方资料
,
以下关于vuex的核心功能说法不正确的是
?
<
br
/><
br
/>
##
答案
Getters是计算属性
,
类似组件的计算属性
,
计算结果不会缓存
##
选项
###
A
Mutations唯一能够对state进行修改的地方
,
在页面中用this
.
$store
.
commit
()
调用
###
B
State是vuex的仓库
,
存放状态是vuex存放数据的地方
###
C
Action是异步操作
,
可以对Mutations中的方法进行操作
data/2.Vue中阶/4.Vue-cli/1.vue-cli脚手架安装/config.json
浏览文件 @
1a0e80b5
...
...
@@ -2,7 +2,9 @@
"node_id"
:
"vue-a10eb688e16c4a02950b28fac1ce5ecb"
,
"keywords"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"exercises.json"
],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
}
\ No newline at end of file
data/2.Vue中阶/4.Vue-cli/2.通过脚手架构建项目/config.json
浏览文件 @
1a0e80b5
...
...
@@ -2,7 +2,9 @@
"node_id"
:
"vue-2230a98a405a4de28ac58228fd5b72d5"
,
"keywords"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"exercises.json"
],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
}
\ No newline at end of file
data/2.Vue中阶/4.Vue-cli/3.vue-cli服务命令/config.json
浏览文件 @
1a0e80b5
...
...
@@ -2,7 +2,9 @@
"node_id"
:
"vue-839da8c27a644e1fae0613354cad4758"
,
"keywords"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"exercises.json"
],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
}
\ No newline at end of file
data/2.Vue中阶/4.Vue-cli/4.vue.config.js的配置/config.json
浏览文件 @
1a0e80b5
...
...
@@ -2,7 +2,9 @@
"node_id"
:
"vue-d80da0184cd44dfd94e41e61e934a6cd"
,
"keywords"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"exercises.json"
],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
}
\ No newline at end of file
data/2.Vue中阶/4.Vue-cli/5.ESLint语法规则插件配置/config.json
浏览文件 @
1a0e80b5
...
...
@@ -2,7 +2,9 @@
"node_id"
:
"vue-18d0903ef9a5424dae41e78f8545b5cf"
,
"keywords"
:
[],
"children"
:
[],
"export"
:
[],
"export"
:
[
"exercises.json"
],
"keywords_must"
:
[],
"keywords_forbid"
:
[]
}
\ No newline at end of file
data/tree.json
浏览文件 @
1a0e80b5
...
...
@@ -611,7 +611,7 @@
}
},
{
"
V
ue-cli"
:
{
"
v
ue-cli"
:
{
"node_id"
:
"vue-b5059c2749d74633ad30145ec28cc22e"
,
"keywords"
:
[],
"children"
:
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录