解决办法:

增加:<script type="module">中增加type的类型是module;

demo1.js

export var name = "yzxing";
export let age = "26";

export function person(name, age) {
    this.name = name;
    this.age = age;
    return `${this.name} ++++ ${this.age}`
}

html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <title>模块</title>
</head>
<body>
<script>
    import {name, age} from "./JS/demo1.js";

    console.log(name, age)
</script>
</body>
</html>

报错:

解决:

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐