dou31797719 2018-08-30 10:22
浏览 436
已采纳

vue路由器组件变量undefined

hello im using router in my php page content tabs, when i first time enter the route variables undefined and change the route go back it works, when i enter from url same as not defined variable shows in vue dev extension?

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');

Template script

<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>
  • 写回答

1条回答 默认 最新

  • duankanjian4642 2018-09-04 11:46
    关注

    It's undefined because the properties on the window object are not being set.

    Instead, you could move the

    <script>
    window.infos = {!! json_encode($response) !!};
    window.characters = {!! json_encode($apicharacters) !!};
    window.episodes = {!! json_encode($episodes) !!};
    </script>
    

    So it is within the HTML <head>. This will then set the properties and values before Vue starts up.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。