Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
瓜皮233
Vue-购物车案例
提交
d1594417
V
Vue-购物车案例
项目概览
瓜皮233
/
Vue-购物车案例
与 Fork 源项目一致
Fork自
inscode / VueJS
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
Vue-购物车案例
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
d1594417
编写于
5月 02, 2023
作者:
6
642b59b229c89a1824b83ed8
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Auto commit
上级
bda2a0b9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
36 addition
and
8 deletion
+36
-8
package.json
package.json
+1
-0
src/App.vue
src/App.vue
+14
-3
src/components/Counter/Counter.vue
src/components/Counter/Counter.vue
+6
-2
src/components/Footer/Footer.vue
src/components/Footer/Footer.vue
+5
-1
src/components/eventBus.js
src/components/eventBus.js
+10
-2
未找到文件。
package.json
浏览文件 @
d1594417
...
...
@@ -9,6 +9,7 @@
"dependencies"
:
{
"
axios
"
:
"
^1.4.0
"
,
"
guess
"
:
"
^1.0.2
"
,
"
mitt
"
:
"
^3.0.0
"
,
"
vue
"
:
"
^3.2.47
"
},
"devDependencies"
:
{
...
...
src/App.vue
浏览文件 @
d1594417
...
...
@@ -9,7 +9,7 @@
<Goods
v-for=
"item in list"
:key=
"item.id"
:title=
"item.goods_name"
:pic=
"item.goods_img"
:chstate=
"item.goods_state"
:id=
"item.id"
:price=
"item.goods_price"
:count=
"item.goods_count"
@
good_check_change=
"updateGoodState"
></Goods>
<Footer
:full_checked=
"allChecked"
:amount=
"amt"
@
changAllGoodsState=
"changeState"
ref=
"FooterRef"
></Footer>
<Footer
:full_checked=
"allChecked"
:amount=
"amt"
:counts=
"allCount"
@
changAllGoodsState=
"changeState"
></Footer>
</div>
</
template
>
...
...
@@ -19,6 +19,7 @@ import axios from 'axios' // 导入 axios 模块
import
Header
from
'
@/components/Header/Header.vue
'
// 导入 Header 组件
import
Goods
from
'
@/components/Goods/Goods.vue
'
// 导入 Goods 组件
import
Footer
from
'
@/components/Footer/Footer.vue
'
import
bus
from
'
@/components/eventBus
'
export
default
{
...
...
@@ -76,14 +77,24 @@ export default {
amt
(){
return
this
.
list
.
filter
(
item
=>
item
.
goods_state
).
reduce
((
t
,
item
)
=>
t
+=
item
.
goods_price
*
item
.
goods_count
,
0
)
},
allCount
(){
return
this
.
list
.
filter
(
item
=>
item
.
goods_state
).
reduce
((
t
,
item
)
=>
t
+=
item
.
goods_count
,
0
)
}
},
created
()
{
// 在实例创建之后请求数据
this
.
initBuyCars
()
bus
.
on
(
'
share
'
,
val
=>
{
this
.
list
.
some
(
item
=>
{
if
(
item
.
id
===
val
.
id
){
item
.
goods_count
=
val
.
value
return
true
}
})
})
// helloWorld(); // 执行该方法
}
}
</
script
>
...
...
src/components/Counter/Counter.vue
浏览文件 @
d1594417
<
template
>
<div
class=
"number-container d-flex justify-content-center align-items-center"
>
<!-- 减 1 的按钮 -->
<button
type=
"button"
class=
"btn btn-light btn-sm"
>
-
</button>
<button
type=
"button"
class=
"btn btn-light btn-sm"
@
click=
"sub"
>
-
</button>
<!-- 购买的数量 -->
<span
class=
"number-box"
>
{{
num
}}
</span>
<!-- 加 1 的按钮 -->
...
...
@@ -28,7 +28,11 @@ export default {
},
methods
:{
add
(){
bus
.
emit
(
'
share
'
,{
id
:
this
.
count_id
,
value
:
this
.
num
+
1
})
},
sub
(){
if
(
this
.
num
===
1
)
return
bus
.
emit
(
'
share
'
,{
id
:
this
.
count_id
,
value
:
this
.
num
-
1
})
}
},
}
...
...
src/components/Footer/Footer.vue
浏览文件 @
d1594417
...
...
@@ -13,7 +13,7 @@
</div>
<!-- 结算按钮 -->
<button
type=
"button"
class=
"btn btn-primary btn-settle"
>
结算(
{{
0
}}
)
</button>
<button
type=
"button"
class=
"btn btn-primary btn-settle"
>
结算(
{{
counts
}}
)
</button>
</div>
</
template
>
...
...
@@ -28,6 +28,10 @@ export default {
amount
:{
type
:
Number
,
default
:
0
},
counts
:{
type
:
Number
,
default
:
0
}
},
methods
:{
...
...
src/components/eventBus.js
浏览文件 @
d1594417
// eventBus.js
/*
import { createApp } from 'vue';
export
default
createApp
({});
const eventBus = createApp({});
export default eventBus; */
// EventBus.js
import
mitt
from
'
mitt
'
;
const
eventBus
=
mitt
();
export
default
eventBus
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录