ZBLOG

要在点击“跟进”按钮时展示一个弹窗,并切换到一个新的 Vue 组件,您可以使用动态组件和 Vue Router。下面是实现这一功能的基本步骤:

1. 使用 Vue Router 创建新组件

首先,创建一个新的 Vue 组件,例如 FollowUpModal.vue

  1. <!-- FollowUpModal.vue -->
  2. <template>
  3. <div>
  4. <h2>跟进记录</h2>
  5. <!-- 跟进的内容和逻辑 -->
  6. <p>您正在跟进: {{ record }}</p>
  7. <a-button @click="close">关闭</a-button>
  8. </div>
  9. </template>
  10. <script setup>
  11. import { ref } from 'vue';
  12. import { useRouter } from 'vue-router';
  13. const props = defineProps(['record']);
  14. const router = useRouter();
  15. const close = () => {
  16. // 返回上一页或关闭 modal 的逻辑
  17. router.back();
  18. };
  19. </script>

2. 配置路由

在你的路由配置文件中,添加对新组件的路由路径,例如:

  1. // router/index.js
  2. import { createRouter, createWebHistory } from 'vue-router';
  3. import FollowUpModal from '../components/FollowUpModal.vue'; // 根据实际路径导入
  4. const routes = [
  5. {
  6. path: '/follow-up',
  7. name: 'FollowUp',
  8. component: FollowUpModal,
  9. },
  10. ];
  11. const router = createRouter({
  12. history: createWebHistory(process.env.BASE_URL),
  13. routes,
  14. });
  15. export default router;

3. 修改原来的表格组件

在原来的表格组件中,将“跟进”按钮的点击事件修改为导航到新页面。

  1. <template>
  2. <a-table
  3. :columns="columns"
  4. :data-source="data"
  5. :scroll="{
  6. x: columns.reduce((sum, col) => sum + (col.width || 0), 0) > 1800 ? undefined : 'max-content'
  7. }"
  8. :pagination="{
  9. current: currentPage,
  10. pageSize: pageSize,
  11. total: totalRecords,
  12. pageSizeOptions: ['10', '20', '30', '40', '100'],
  13. onShowSizeChange: handlePageSizeChange,
  14. onChange: handlePageChange,
  15. showQuickJumper: true,
  16. showSizeChanger: true,
  17. showTotal: (total, range) => `显示 ${range[0]}~${range[1]} 条记录,共 ${total} 条记录`
  18. }"
  19. >
  20. <template #bodyCell="{ column, record }">
  21. <template v-if="column.key === 'operation'">
  22. <a-button @click="openModal('edit', record)">编辑</a-button>
  23. <a-button @click="goToFollowUp(record)">跟进</a-button> <!-- 修改这里 -->
  24. <a-button @click="complete(record)">完成</a-button>
  25. </template>
  26. </template>
  27. </a-table>
  28. </template>
  29. <script setup>
  30. // ...其余代码保持不变...
  31. const goToFollowUp = (record) => {
  32. // 使用 vue-router 导航到跟进页面,并将记录作为参数传递过去
  33. router.push({ name: 'FollowUp', query: { recordId: record.id } });
  34. };
  35. </script>

注意事项

  • 确保您的 Vue Router 和其他依赖项已正确安装和设置。
  • FollowUpModal 中处理从 URL 获取传递的数据,比如使用 useRoute 获取参数并显示相应的记录信息。

这样,当用户点击“跟进”按钮时,会导航到新的 Vue 页面并展示相关信息。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=22460

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?