Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wordpress Vuejs组件没有';当路由与路由器链接发生变化时不显示_Wordpress_Vue.js_Vue Router - Fatal编程技术网

Wordpress Vuejs组件没有';当路由与路由器链接发生变化时不显示

Wordpress Vuejs组件没有';当路由与路由器链接发生变化时不显示,wordpress,vue.js,vue-router,Wordpress,Vue.js,Vue Router,我正在用Vuejs创建一个带有WP Rest API的主题。我已经创建了博客标题的动态路由,并与路由器链接链接。当我点击一个标题时,url会改变,但组件不会显示出来。我只得到一张空白页。这是我的密码: index.php <div class="wrapper"> <div id="app"> <router-view></router-view> </div> </div> &l

我正在用Vuejs创建一个带有WP Rest API的主题。我已经创建了博客标题的动态路由,并与路由器链接链接。当我点击一个标题时,url会改变,但组件不会显示出来。我只得到一张空白页。这是我的密码:

index.php

<div class="wrapper"> 
    <div id="app">
        <router-view></router-view>
    </div>
</div>    

<template id="post-list-template">
    <div class="container">
        <div class="post-list">
            <article v-for="post in posts">
                <router-link :to="{name:'post', params:{slug: post.slug}}"><h2>{{ post.title.rendered }}</h2></router-link>
                <p v-html="post.excerpt.rendered"></p>
            </article>
        </div>
    </div>
</template>


<template id="single-post-template">
    <h2>Hello World</h2>
</template>

如果遇到任何错误,请尝试
Vue.component
而不是
Vue.extend
以查看
singlePost
。无错误。点击链接时,“Hello World”会出现一秒钟。好的,我发现了错误。第二条路径-“/post/:slug”的开头应该有一条斜线
 var singlePost= Vue.extend({
    template: '#single-post-template'

});


var router = new VueRouter({
    routes: [
        {path: '/', component: postList},
        {path:'post/:slug', name:'post', component: singlePost}
    ]
});



new Vue({
    el:'#app',
    router: router,
});