"未注册的Vue路由"
P粉338969567
P粉338969567 2023-09-11 20:11:48
0
1
359

我正在尝试向现有的Web应用程序添加新的路由:

这是入口点:

// main.js
import router from './router';

... etc

new Vue({
  router,
  ... etc
  render: (h) => h(App),
}).$mount('#app');

这是路由器:

// router/index.js
import AffiliateLinks from '../modules/affiliate_links/AffiliateLinks.vue';

Vue.use(VueRouter);

const routes = [
... etc
  {
    path: '/affiliate-links/client',
    component: AffiliateLinks,
    meta: {
      restricted: 'CLIENT',
    },
  },
];

const router = new VueRouter({
  routes,
});

router.beforeEach((to, from, next) => {
  ... etc

  // check routes restricted by distribution channel
  if (to.meta?.restricted && !to.meta.restricted.includes(store.state.user.access.distribution_channel)) {
    next({ path: '/' });
    return;
  }

  // user is logged in, allow requested routing
  next();
});

export default router;

// 这是父组件:

// AffiliateLinks.vue
<template>
  <v-container fluid>
    <v-row align-content="space-between">
      <h3>String Here</h3>
      <v-btn @click.stop="showAffiliateLinksModal = true" />
    </v-row>
    <AffiliateLinksModal v-model="showAffiliateLinksModal" @close="showAffiliateLinksModal = false" />
  </v-container>
</template>

<script>
import AffiliateLinksModal from './AffiliateLinksModal.vue';
export default {
  name: 'AffiliateLinks',
  components: {
    AffiliateLinksModal,
  },
  data() {
    return {
      showAffiliateLinksModal: false,
    };
  },
};
</script>

// 这是子组件:

// AffiliateLinksModal.vue
<template>
  <v-dialog v-model="value" max-width="450px">
    <v-card>
      <v-card-actions>
        <v-btn @click.stop="$emit('close')">String Here</v-btn>
      </v-card-actions>
    </v-card>
  </v-dialog>
</template>

<script>
export default {
  name: 'AffiliateLinksModal',
  props: ['value'],
};
</script>

一切看起来都很简单,但是当我检查Vue开发工具时,我看不到新的路由,当我点击组件,比如

<v-card :to="url">
  ... etc
</v-card>

没有任何反应。

P粉338969567
P粉338969567

全部回复(1)
P粉605233764

我弄清楚了。

我结束了一天的工作,并将我的更改提交到远程仓库。 这时我注意到路由器上的更改不见了。 我可以在文本编辑器和本地Git工作更改中看到这些更改,但它们无法推送到远程仓库。

值得注意的是:我删除了本地仓库,并在同一位置重新克隆,但问题仍然存在。

我创建了一个临时文件夹,问题就解决了...

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!