|
可以使用this.fire(type, data)向父组件传事件。type是父组件接收者名字,data的数据。
例如:
父组件:
- <template>
- <view class="page" >
- <goods-action onAddCart="addCart"></goods-action>
- </view>
- </template>
- <script>
- import GoodsAction from "../../components/goods-action.stml";
- export default {
- name: "goods-add",
- methods: {
- addCart() {
- api.toast({msg: '父组件收到事件'});
- }
- }
- }
- </script>
复制代码
子组件:
- <template name="goods-action">
- <view @click="addCart">
- <text class="btn-text">加入购物车</text>
- </view>
- </template>
- <script>
- export default {
- name: "goods-action",
- methods: {
- addCart() {
- this.fire('addCart')
- }
- }
- }
- </script>
复制代码 |
|