index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <!--components/shopping-cart/shopping-cart.wxml-->
  3. <view class="contact ddflex" id="contact" @tap="jumpCart('/pages/cart/cart')">
  4. <image src="../../static/pages/images/cart.png"></image>
  5. <text class="dots-cart dflex" v-if="count > 0">{{count}}</text>
  6. </view>
  7. </template>
  8. <script>
  9. const app = getApp();
  10. const req = require("../../utils/request");
  11. export default {
  12. data() {
  13. return {
  14. count: ""
  15. };
  16. },
  17. components: {},
  18. props: {
  19. //是否更新
  20. isUpdate: {
  21. type: Boolean,
  22. default: false
  23. }
  24. },
  25. watch: {
  26. "isUpdate": function(isUpdate) {
  27. // console.log('需要更新消息', isUpdate);
  28. if (!this.isReady) return;
  29. this.getCount();
  30. }
  31. },
  32. mounted() {
  33. // console.log('ready');
  34. this.isReady = true;
  35. this.getCount();
  36. },
  37. methods: {
  38. getCount() {
  39. req.getRequest('/api/purchase/count', {
  40. purchaseType: 1
  41. }, data => {
  42. this.setData({
  43. count: data
  44. });
  45. // console.log(this);
  46. });
  47. },
  48. goshopCar() {
  49. uni.navigateTo({
  50. url: '/pages/cart/cart'
  51. });
  52. },
  53. jumpCart(url) {
  54. if (req.getStorage('cartTab')) {
  55. uni.$emit('tabClick', 'cart');
  56. } else {
  57. // app.globalData.openPage(url)
  58. uni.navigateTo({
  59. url: url
  60. });
  61. }
  62. }
  63. }
  64. };
  65. </script>
  66. <style>
  67. @import "./index.css";
  68. </style>