gpt4 book ai didi

javascript - 当我使用 vue-router 时,我的组件的内容没有显示

转载 作者:行者123 更新时间:2023-11-30 19:35:38 24 4
gpt4 key购买 nike

我是 vue 新手。对不起,如果这是一个愚蠢的问题。我正在使用 vue-router 路由到一个组件。当我点击路由器链接时,我的 url 发生了变化,但组件的内容没有显示。我在开发人员工具中没有收到任何错误。如果您能提供帮助,那将是一个巨大的帮助。

我在这里尝试了有关此问题的所有答案,但仍然无法正常工作。

源/App.vue

<template>
<div id="app">
<router-link to="/toread">Go toread</router-link>
<router-view></router-view>
</div>
</template>
<script>
import toread from './components/toread.vue';
export default {
name: 'app',
components:{
toread
},
}
</script>

src/components/toread.vue

<template>
<div>
<h1>toread</h1>
</div>
</template>
<script>
export default {

}
</script>
<style scoped>

</style>

源代码/main.js

import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import Routes from './routes'
import toread from './components/toread.vue'

Vue.use(VueRouter)
const router = new VueRouter({
Routes
});
new Vue({
el: '#app',
render: h => h(App),
router
})

src/routes.js

import toread from './components/toread.vue'
export default[
{path:'/toread', component:toread},
]

我希望点击路由器链接并显示来自 toread 组件的 h1 标签。

最佳答案

Routes 更改为 routes: Routes

const router = new VueRouter({
routes: Routes
});

关于javascript - 当我使用 vue-router 时,我的组件的内容没有显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55979989/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com