厦门建设网站企业,做一个商城网站需要提交那些文件,server酱 wordpress,大港油田建设官方网站文章目录 作用流程 作用
多个页面需要一个功能时#xff0c;用mixins进行复用#xff0c;使代码更简洁
流程
1 新建一个 mixin 文件 mixins/loginConfirm.js
export default {methods: {// 是否需要弹登录确认框// (1) 需要#xff0c;返回 true#xff0c;并直接弹出登… 文章目录 作用流程 作用
多个页面需要一个功能时用mixins进行复用使代码更简洁
流程
1 新建一个 mixin 文件 mixins/loginConfirm.js
export default {methods: {// 是否需要弹登录确认框// (1) 需要返回 true并直接弹出登录确认框// (2) 不需要返回 falseloginConfirm () {if (!this.$store.getters.token) {this.$dialog.confirm({title: 温馨提示,message: 此时需要先登录才能继续操作哦,confirmButtonText: 去登陆,cancelButtonText: 再逛逛}).then(() {// 如果希望跳转到登录 登录后能回跳回来需要在跳转去携带参数 (当前的路径地址)// this.$route.fullPath (会包含查询参数)this.$router.replace({path: /login,query: {backUrl: this.$route.fullPath}//route.fullPath 包含从基本URL后开始的路径假设基本URLbase URL为 /app并且当前路由为 /app/home?a1那么route.path的值将是 /home?a1})}).catch(() {})return true}return false}}
}
2 页面中导入混入方法
import loginConfirm from /mixins/loginConfirmexport default {name: ProDetail,mixins: [loginConfirm],...
}3 页面中调用 混入的方法
async addCart () {if (this.loginConfirm()) {return}const { data } await addCart(this.goodsId, this.addCount, this.detail.skuList[0].goods_sku_id)this.cartTotal data.cartTotalthis.$toast(加入购物车成功)this.showPannel falseconsole.log(this.cartTotal)
},goBuyNow () {if (this.loginConfirm()) {return}this.$router.push({path: /pay,query: {mode: buyNow,goodsId: this.goodsId,goodsSkuId: this.detail.skuList[0].goods_sku_id,goodsNum: this.addCount}})
}