当前位置:首页 > VUE

vue实现物流追踪

2026-02-17 13:23:00VUE

Vue实现物流追踪功能

物流追踪功能通常需要结合后端API数据展示物流节点的动态信息。以下为Vue实现方案的核心要点:

数据准备

  • 物流节点数据格式建议:
    nodes: [
      { time: '2023-01-01 10:00', status: '已发货', desc: '快件已揽收' },
      { time: '2023-01-02 15:30', status: '运输中', desc: '到达广州转运中心' },
      // ...
    ]

时间轴组件实现

vue实现物流追踪

<template>
  <div class="logistics-track">
    <div v-for="(node, index) in nodes" :key="index" class="track-node">
      <div class="node-time">{{ node.time }}</div>
      <div class="node-status">{{ node.status }}</div>
      <div class="node-desc">{{ node.desc }}</div>
    </div>
  </div>
</template>

样式优化

.logistics-track {
  position: relative;
  padding-left: 20px;
}
.track-node {
  position: relative;
  padding-bottom: 20px;
  border-left: 2px solid #1890ff;
}
.track-node:last-child {
  border-left-color: transparent;
}
.track-node::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #1890ff;
}

动态效果增强

vue实现物流追踪

  • 添加当前节点高亮效果:
    computed: {
      activeNodes() {
        return this.nodes.map((node, index) => ({
          ...node,
          isActive: index <= this.currentStep
        }))
      }
    }

API集成

methods: {
  async fetchLogistics() {
    try {
      const res = await axios.get('/api/logistics', {
        params: { orderId: this.orderId }
      })
      this.nodes = res.data.nodes
    } catch (error) {
      console.error(error)
    }
  }
}

第三方组件方案

  • 可使用vantSteps组件快速实现:
    <van-steps direction="vertical" :active="activeStep">
      <van-step v-for="node in nodes" :key="node.time">
        <h3>{{ node.status }}</h3>
        <p>{{ node.time }}</p>
        <p>{{ node.desc }}</p>
      </van-step>
    </van-steps>

注意事项

  • 物流节点数据需按时间倒序排列
  • 移动端需考虑响应式布局
  • 长时间未更新的节点需添加异常状态提示
  • 建议添加物流公司logo和联系方式

实际实现时需根据具体业务需求调整UI样式和数据交互逻辑,建议通过vuexpinia管理物流状态数据。

标签: 物流vue
分享给朋友:

相关文章

vue实现按钮刷新

vue实现按钮刷新

Vue 实现按钮刷新功能 在 Vue 中实现按钮刷新功能可以通过多种方式实现,具体取决于刷新需求是局部刷新还是全局刷新。以下是几种常见的方法: 使用 window.location.reload()…

vue怎么实现页面返回

vue怎么实现页面返回

Vue 实现页面返回的方法 在 Vue 中实现页面返回功能,可以通过以下几种方式完成,具体取决于项目使用的路由模式和技术栈。 使用 Vue Router 的编程式导航 通过 this.$router…

vue实现3d宇宙

vue实现3d宇宙

Vue实现3D宇宙效果 使用Three.js库 Three.js是一个强大的JavaScript 3D库,可以轻松集成到Vue项目中。安装Three.js依赖: npm install three…

vue grid实现

vue grid实现

Vue Grid 实现方法 在 Vue 中实现网格布局可以通过多种方式完成,包括使用原生 CSS Grid、第三方组件库或自定义组件。以下是几种常见方法: 使用原生 CSS Grid 通过 Vue…

vue 实现列表

vue 实现列表

Vue 实现列表的方法 在 Vue 中实现列表通常使用 v-for 指令,结合数组或对象数据渲染动态列表。以下是几种常见的实现方式: 基础列表渲染 使用 v-for 指令遍历数组,渲染列表项。ite…

vue实现文字

vue实现文字

Vue 中实现文字显示的方法 在 Vue 中实现文字显示可以通过多种方式,包括插值表达式、指令、组件等。以下是几种常见的实现方法: 插值表达式 使用双大括号 {{ }} 进行文本插值,这是 Vue…