您好,我在php页面的内容标签中使用路由器,当我第一次输入未定义的路由变量并更改路由时,它可以正常工作,当我从url输入与在vue dev扩展名中未定义的变量相同时? >
app.js
const routes = [
{
path: '/',
component: infotab,
name: 'Info'
},
{ path: '/characters', component: charactertab, name: 'home' },
{ path: '/watch', component: watchtab },
{ path: '/downloads', component: downloadtab }
]
const router = new VueRouter({
routes,
});
var tabb = new Vue({
router,
el: "#app",
}).$mount('#app');
模板脚本
<script>
export default {
data () {
return {
details: window.infos,
characters: window.characters,
episodes: window.episodes,
}
}
}
</script>
single.blade.php
<div data-v-20e267b2="" data-v-aaf71b06="" class="overview">
<router-view></router-view>
</div>
</div>
<script>
window.infos = {!! json_encode($response) !!};
window.characters = {!! json_encode($apicharacters) !!};
window.episodes = {!! json_encode($episodes) !!};
</script>
答案 0 :(得分:0)
由于未设置window
对象的属性,因此未定义。
相反,您可以移动
<script>
window.infos = {!! json_encode($response) !!};
window.characters = {!! json_encode($apicharacters) !!};
window.episodes = {!! json_encode($episodes) !!};
</script>
因此它在HTML <head>
中。然后,这将在Vue启动之前设置属性和值。