javascript - weex中,使用router-view之后,在playground中打开变空白了

 patrick0129_645 发布于 2022-11-10 10:23

3月5日新情况

将原来的router.js写法进行了修改,现在playground里面运行不会一片空白了,但是初始的router-view无法显示,只有在点击后路由跳转了才正常显示,请问是什么原因?

入口js

import Vue from 'vue';
import VueRouter from 'vue-router';
import App from './index.vue';

import index from './components/index.vue';
import index2 from './components/index2.vue';

Vue.use(VueRouter);//转载插件

Vue.config.silent = false;
Vue.config.devtools = true;

const router=new VueRouter({
    routes:[
        {
            path:'/',
            component: index
        },
        {
            path:'/a',
            component: index2
        }
    ]
});

new Vue(Vue.util.extend({ el: '#root', router}, App))

入口vue





weex debug结果

[undefined:6:43] ReferenceError: Can't find variable: window
anonymous
Dt@main.js:3:31709
main.js:7:1121

问题

一开始使用的是https://zhuanlan.zhihu.com/p/...的初始架构,在其基础上增加vue-router,但是一把router-view加进去在playground中跑就变成一片空白了

这是index.vue的代码




还有app.js的代码

import Vue from 'vue';
import VueRouter from 'vue-router';
import router from './routers';
import App from './index.vue'

Vue.use(VueRouter);//转载插件

Vue.config.silent = false;
Vue.config.devtools = true;

const route=new VueRouter({
    routes:router,
    base:__dirname
});

new Vue({
  el: '#root',
  router:route,
  render: h => h(App)
})

浏览器上面是可以跑的,路由切换也没问题,但是就是playground上面空白,请问是什么原因?

2 个回答
  • 问题都解决了,对于初始router-view的不显示,只要在初始页面的生命周期中添加跳转就好了,谢谢大家

    2022-11-12 01:46 回答
  • 使用如下代码测试一下

    new Vue(Vue.util.extend({
        el: '#root',
        router
    }, App))
    2022-11-12 01:46 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有