index.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <!--components/shopping-cart/shopping-cart.wxml-->
  3. <view class="contact" id="contact" @tap="goshopCar">
  4. <image src="/static/pages/images/cart.png"></image>
  5. <text class="dots dflex" v-if="count > 0">{{count}}</text>
  6. </view>
  7. </template>
  8. <script>
  9. // components/shopping-cart/shopping-cart.js
  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.switchTab({
  50. url: '/pages/cart/cart'
  51. });
  52. }
  53. }
  54. };
  55. </script>
  56. <style>
  57. @import "./index.css";
  58. </style>