index.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <view class="hc-breadcrumb-bar">
  3. <view class="breadcrumb-bar">
  4. <template v-for="(item, index) in datas" :key="index">
  5. <view class="breadcrumb-item"
  6. :class="datas.length-1 === index ? 'active': ''"
  7. @click="itemClick(item, index)"
  8. >
  9. <text class="name">{{item.name}}</text>
  10. <text class="i-ri-arrow-right-s-line icon"/>
  11. </view>
  12. </template>
  13. </view>
  14. </view>
  15. </template>
  16. <script setup>
  17. import {ref, watch} from "vue";
  18. //初始变量
  19. const props = defineProps({
  20. data: {
  21. type: Array,
  22. default: () => ([])
  23. }
  24. });
  25. //变量
  26. const datas = ref(props.data)
  27. const emit = defineEmits(['change'])
  28. //监听变化
  29. watch(() => [
  30. props.data
  31. ], ([data]) => {
  32. datas.value = data
  33. })
  34. //被点击
  35. const itemClick = (item, index) => {
  36. if(index !== datas.value.length - 1) {
  37. emit('change', item, index)
  38. }
  39. }
  40. </script>
  41. <style lang="scss">
  42. @import "./style.scss";
  43. </style>