ZBLOG

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

1. 使用 Vue Router 创建新组件

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

<!-- FollowUpModal.vue -->
<template>
  <div>
    <h2>跟进记录</h2>
    <!-- 跟进的内容和逻辑 -->
    <p>您正在跟进: {{ record }}</p>
    <a-button @click="close">关闭</a-button>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const props = defineProps(['record']);
const router = useRouter();

const close = () => {
  // 返回上一页或关闭 modal 的逻辑
  router.back();
};
</script>

2. 配置路由

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

// router/index.js
import { createRouter, createWebHistory } from 'vue-router';
import FollowUpModal from '../components/FollowUpModal.vue'; // 根据实际路径导入

const routes = [
  {
    path: '/follow-up',
    name: 'FollowUp',
    component: FollowUpModal,
  },
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;

3. 修改原来的表格组件

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

<template>
  <a-table
    :columns="columns"
    :data-source="data"
    :scroll="{
      x: columns.reduce((sum, col) => sum + (col.width || 0), 0) > 1800 ? undefined : 'max-content'
    }"
    :pagination="{
      current: currentPage,
      pageSize: pageSize,
      total: totalRecords,
      pageSizeOptions: ['10', '20', '30', '40', '100'],
      onShowSizeChange: handlePageSizeChange,
      onChange: handlePageChange,
      showQuickJumper: true,
      showSizeChanger: true,
      showTotal: (total, range) => `显示 ${range[0]}~${range[1]} 条记录,共 ${total} 条记录`
    }"
  >
    <template #bodyCell="{ column, record }">
      <template v-if="column.key === 'operation'">
        <a-button @click="openModal('edit', record)">编辑</a-button>
        <a-button @click="goToFollowUp(record)">跟进</a-button> <!-- 修改这里 -->
        <a-button @click="complete(record)">完成</a-button>
      </template>
    </template>
  </a-table>
</template>

<script setup>
// ...其余代码保持不变...

const goToFollowUp = (record) => {
   // 使用 vue-router 导航到跟进页面,并将记录作为参数传递过去
   router.push({ name: 'FollowUp', query: { recordId: record.id } });
};
</script>

注意事项

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

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


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

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

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?