gpt4 book ai didi

javascript - 为什么我的 .vue 组件未定义?

转载 作者:搜寻专家 更新时间:2023-10-30 22:34:13 25 4
gpt4 key购买 nike

我正在使用 parcel-plugin-vue 从文件编译最简单的 .vue 组件。

编译运行,没有错误,但在我的浏览器中显示空白页面,没有任何内容。我可以在我的 main.js 文件中看到 import .vue 组件在运行时未定义。请问这是为什么?

IDE

主要.js

import Vue from '../node_modules/vue/dist/vue';
import { Welcome } from './app/widgets/welcome/welcome.vue'; //this is undefined at runtime, but doesn't error

window.onload = startVue;

function startVue()
{
new Vue({
'el': '#app',
'template': Welcome,
'components': { Welcome }
});
}

欢迎.vue

<template>
<div>
<h1>Welcome</h1>
</div>
</template>

<script>
export default
{
components: {}
}
</script>

<style>
</style>

包.json

{ 
"main": "index.js",
"devDependencies": {
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^0.28.7",
"eslint": "^4.14.0",
"parcel-bundler": "^1.3.1",
"parcel-plugin-vue": "^1.4.0"
},
"dependencies": {
"vue": "^2.5.13",
"vue-material": "^1.0.0-beta-7",
"vue-router": "^3.0.1",
"vuex": "^3.0.1"
}
}

为了编译,我正在运行 ./node_modules/.bin/parcel index.html

最佳答案

Welcome.vue 组件中没有名为 Welcome 的导出,因此您无法使用花括号语法导入它。导入应该在没有花括号的情况下工作:

import Welcome from './app/widgets/welcome/welcome.vue';

关于javascript - 为什么我的 .vue 组件未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48047325/

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