Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夜猫逐梦
MyOpen
提交
2f52f23e
M
MyOpen
项目概览
夜猫逐梦
/
MyOpen
通知
2
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
MyOpen
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2f52f23e
编写于
9月 12, 2023
作者:
S
sw_pc
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Count组件测试
上级
89e94858
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
79 addition
and
2 deletion
+79
-2
course/vue2/vuex/heima/src/App.vue
course/vue2/vuex/heima/src/App.vue
+9
-2
course/vue2/vuex/heima/src/components/Count.vue
course/vue2/vuex/heima/src/components/Count.vue
+45
-0
course/vue2/vuex/heima/src/store/index.js
course/vue2/vuex/heima/src/store/index.js
+25
-0
未找到文件。
course/vue2/vuex/heima/src/App.vue
浏览文件 @
2f52f23e
<
template
>
<
template
>
<div
id=
"app"
>
<div
id=
"app"
>
<img
alt=
"Vue logo"
src=
"./assets/logo.png"
>
<img
alt=
"Vue logo"
src=
"./assets/logo.png"
>
<HelloWorld
msg=
"Welcome to Your Vue.js App"
/>
<Count
msg=
"Welcome to Your Vue.js App"
/>
<HelloWorld
id=
"hello"
msg=
"Welcome to Your Vue.js App"
/>
</div>
</div>
</
template
>
</
template
>
<
script
>
<
script
>
import
HelloWorld
from
'
./components/HelloWorld.vue
'
import
HelloWorld
from
'
./components/HelloWorld.vue
'
import
Count
from
'
./components/Count.vue
'
export
default
{
export
default
{
name
:
'
App
'
,
name
:
'
App
'
,
components
:
{
components
:
{
HelloWorld
HelloWorld
,
Count
}
}
}
}
</
script
>
</
script
>
...
@@ -25,4 +28,8 @@ export default {
...
@@ -25,4 +28,8 @@ export default {
color
:
#2c3e50
;
color
:
#2c3e50
;
margin-top
:
60px
;
margin-top
:
60px
;
}
}
#hello
{
display
:
none
;
}
</
style
>
</
style
>
course/vue2/vuex/heima/src/components/Count.vue
0 → 100644
浏览文件 @
2f52f23e
<
template
>
<div>
<h1>
当前求和为:
{{
$store
.
getters
.
bigSum
}}
</h1>
<select
v-model.number=
"n"
>
<option
value=
"1"
>
1
</option>
<option
value=
"2"
>
2
</option>
<option
value=
"3"
>
3
</option>
</select>
<button
@
click=
"increment"
>
+
</button>
<button
@
click=
"decrement"
>
-
</button>
<button
@
click=
"incrementOdd"
>
当前求和为奇数再加
</button>
<button
@
click=
"incrementWait"
>
等一等再加
</button>
</div>
</
template
>
<
script
>
export
default
{
name
:
"
CountA
"
,
data
()
{
return
{
n
:
1
,
//用户选择的数字
};
},
methods
:
{
increment
()
{
this
.
$store
.
commit
(
"
ADD
"
,
this
.
n
);
},
decrement
()
{
this
.
$store
.
commit
(
"
SUBTRACT
"
,
this
.
n
);
},
incrementOdd
()
{
this
.
$store
.
dispatch
(
"
addOdd
"
,
this
.
n
);
},
incrementWait
()
{
this
.
$store
.
dispatch
(
"
addWait
"
,
this
.
n
);
},
},
};
</
script
>
<
style
>
button
{
margin-left
:
5px
;
}
</
style
>
course/vue2/vuex/heima/src/store/index.js
浏览文件 @
2f52f23e
...
@@ -5,12 +5,37 @@ Vue.use(Vuex)
...
@@ -5,12 +5,37 @@ Vue.use(Vuex)
export
default
new
Vuex
.
Store
({
export
default
new
Vuex
.
Store
({
state
:
{
state
:
{
sum
:
0
//当前的和
},
},
getters
:
{
getters
:
{
bigSum
(
state
)
{
console
.
log
(
state
)
return
state
.
sum
*
10
}
},
},
mutations
:
{
mutations
:
{
ADD
(
state
,
value
){
console
.
log
(
"
mutations ADD
"
)
state
.
sum
+=
value
},
SUBTRACT
(
state
,
value
){
console
.
log
(
"
mutations SUBTRACT
"
)
state
.
sum
-=
value
}
},
},
actions
:
{
actions
:
{
addOdd
(
context
,
value
){
console
.
log
(
"
actions中的addOdd被调用了
"
)
if
(
context
.
state
.
sum
%
2
){
context
.
commit
(
'
ADD
'
,
value
)
}
},
addWait
(
context
,
value
){
console
.
log
(
"
actions中的addWait被调用了
"
)
setTimeout
(()
=>
{
context
.
commit
(
'
ADD
'
,
value
)
},
500
)
},
},
},
modules
:
{
modules
:
{
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录