fav.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="container">
  3. <uni-card is-full :is-shadow="false">
  4. <text class="uni-h6">用于收藏功能,可点击切换选中、不选中的状态。</text>
  5. </uni-card>
  6. <uni-section title="基本用法" type="line">
  7. <view class="example-body">
  8. <uni-fav :checked="checkList[0]" class="favBtn" @click="favClick(0)" />
  9. <uni-fav :checked="checkList[1]" :star="false" class="favBtn" @click="favClick(1)" />
  10. <uni-fav :checked="checkList[2]" class="favBtn" :circle="true" bg-color="#dd524d" bg-color-checked="#007aff"
  11. fg-color="#ffffff" fg-color-checked="#ffffff" @click="favClick(2)" />
  12. <uni-fav :checked="checkList[3]" class="favBtn" bg-color="#f8f8f8" bg-color-checked="#eeeeee" fg-color="#333333"
  13. fg-color-checked="#333333" @click="favClick(3)" />
  14. </view>
  15. </uni-section>
  16. <uni-section title="自定义文字" type="line">
  17. <view class="example-body">
  18. <uni-fav :checked="checkList[4]" :content-text="contentText" @click="favClick(4)" />
  19. </view>
  20. </uni-section>
  21. <uni-section title="在自定义导航栏使用" type="line">
  22. <uni-nav-bar style="width: 100%;" :fixed="false" left-icon="left" title="标题" color="#333333" background-color="#FFFFFF">
  23. <template v-slot:right>
  24. <uni-fav :checked="checkList[5]" :circle="true" @click="favClick(5)" />
  25. </template>
  26. </uni-nav-bar>
  27. </uni-section>
  28. <view class="example-body example-body-fullWidth">
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. export default {
  34. components: {},
  35. data() {
  36. return {
  37. checkList: [false, false, false, false, false, false],
  38. contentText: {
  39. contentDefault: '追番',
  40. contentFav: '已追番'
  41. }
  42. }
  43. },
  44. methods: {
  45. favClick(index) {
  46. this.checkList[index] = !this.checkList[index]
  47. console.log(this.checkList[index]);
  48. this.$forceUpdate()
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss">
  54. .example-body {
  55. display: flex;
  56. padding: 10px 15px;
  57. }
  58. /* #ifdef MP-ALIPAY */
  59. .uni-fav {
  60. margin-left: 20rpx;
  61. }
  62. /* #endif */
  63. .favBtn {
  64. margin: 0 20rpx 20rpx 0;
  65. }
  66. .example-body-fullWidth {
  67. padding: 32rpx 0;
  68. }
  69. .example-body-first {
  70. /* #ifndef APP-PLUS-NVUE */
  71. display: flex;
  72. /* #endif */
  73. flex-direction: row;
  74. justify-content: flex-start;
  75. }
  76. .favBtn-nav {
  77. // left:-50rpx;
  78. }
  79. </style>