子页面怎么调用父页面let声明的变量

最近用es6的语法写代码,发现父页面用let声明的变量子页面调用不到,报undefined,由于用了freemark,避免和es6的字符模板语法冲突,js是写在了js文件中。换了var 就行,有大佬知道父页面用let怎么声明才能被子页面调用到么,怎么提升父页面let声明的作用域
父页面 companyInfo.html:

let vue = new Vue({
    el: '#app',
    data: {
        companyInfo: {},
    },
    methods: {
        select: function () {
            $.ajax({
                url: `${basePath}customer/info/selectCompanyInfo`,
                type: 'post',
                data: {},
                success: ({code, msg, data}) => {
                    vue.companyInfo = data;
                },
                error: () => {
                    layer.msg('系统错误');
                },
            });
        },
        openEditWindow: function () {
            layer.open({
                type: 2,
                skin: 'layui-layer-molv',
                title: '修改信息',
                area: ['768px', '400px'],
                resize: false,
                shadeClose: false,
                content: 'companyInfo_update.html',
            });
        },
    },
    created: function () {
        this.select();
    }
});
export default vue;

子页面 companyInfo_update.html:

import vue from 'companyInfo.html';
let vue = new Vue({
    el: '#app',
    data: {
        companyInfo: {
            id: '',
            address: '',
            linkman: '',
            tel: '',
            mobile: '',
            fax: '',
            email: '',
            postcode: '',
            netAddress: '',
        }
    },
    methods: {
        getCompanyInfo:function () {
            $.ajax({
                url: `../../customer/info/selectCompanyInfo`,
                type: 'post',
                data: {},
                success: ({code, msg, data: {id, address, linkman, tel, mobile, fax, email, postcode, netAddress}}) => {
                    vue.companyInfo.id = id;
                    vue.companyInfo.address = address;
                    vue.companyInfo.linkman = linkman;
                    vue.companyInfo.tel = tel;
                    vue.companyInfo.mobile = mobile;
                    vue.companyInfo.fax = fax;
                    vue.companyInfo.email = email;
                    vue.companyInfo.postcode = postcode;
                    vue.companyInfo.netAddress = netAddress;
                },
                error: () => {
                    layer.msg('系统错误');
                },
            });
        },
        update: function () {
            let a = window.parent.vue;
            // parent.vue.select();
            // let index = parent.layer.getFrameIndex(window.name);
            // parent.layer.close(index);
        },
        goBack: () => {
            window.location.href = `companyInfo.html`;
        },
    },
    created: function () {
        this.getCompanyInfo()
    }
});
阅读 3k
2 个回答

在父页面最后一行加上
export default vue

在子页面第一行加上
import vue from 'xxx'; // xxx指的是子页面访问父页面的路径

相关资料请查阅模块

看了下更新后的,是不是编译时没设置是用的es6?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题