gpt4 book ai didi

javascript - 导入脚本顺序错误,函数未定义

转载 作者:太空宇宙 更新时间:2023-11-04 15:30:34 24 4
gpt4 key购买 nike

我有一个像这样的 vuejs 组件 (map.vue):

<script> 
import '../../assets/js/map.js'

export default {
name: 'home',
data () {
return {
init_data: {},
}
},
created: function() {
this.init_data = window.get_init_data(this.view, function(response) {
document.title = response.body.page_title;
init_map(some_arguments);
});
}
}
</script>

map.js:

const key = ******;
function init_map(some_args) {
...
}

错误:

[Vue warn]: Error in created hook: "ReferenceError: init_map is not defined"

事实上,在签名之前检查其调用的函数的源代码。

注意:我不想在 webpack 条目中包含 map.js,因为我只需要在一个组件 (map.vue) 中使用此脚本。

最佳答案

试试这个

测试.js

export function writeHello() {
console.log('hello');
}

*****.vue

import {writeHello} from './../test.js';

export default {
created() {
writeHello();
}
}

关于javascript - 导入脚本顺序错误,函数未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44823479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com