lhk*_*lhk 6 typescript vue.js vue-component parceljs
我正在遵循 Vue入门指南,并且想让这个简单的示例发挥作用:
HTML:
<div id="counter">
Counter: {{ counter }}
</div>
Run Code Online (Sandbox Code Playgroud)
打字稿:
const Counter = {
data() {
return {
counter: 0
}
}
}
Vue.createApp(Counter).mount('#counter')
Run Code Online (Sandbox Code Playgroud)
为此,我安装了:
npm install vue@next
Run Code Online (Sandbox Code Playgroud)
我用以下命令导入它:
import * as Vue from "vue";
Run Code Online (Sandbox Code Playgroud)
HTML 片段和 Typescript 脚本被放入一个index.html文件中。它与 捆绑parcel并在本地托管serve。
Vue 提供 Typescript 类型,如果我像这样导入 Vue,它们会被正确拾取。但是,当我打开托管项目时,出现错误消息:
Component provided template option but runtime compilation is not supported in this build of Vue. Configure your bundler to alias "vue" to "vue/dist/vue.esm-bundler.
Run Code Online (Sandbox Code Playgroud)
我听从了建议并将导入更改为:
import * as Vue from "vue/dist/vue.esm-bundler";
Run Code Online (Sandbox Code Playgroud)
这使得示例代码按预期工作。但现在打字信息丢失了。
将 Vue 与 Typescript 和捆绑器结合起来,同时允许运行时编译的正确方法是什么?
| 归档时间: |
|
| 查看次数: |
558 次 |
| 最近记录: |