vue.js - vue with parcel 无法正确渲染
问题描述
下面的简单过程不起作用,虽然我不明白为什么......使用:npm vue parcel
mkdir samat
cd samat
npm init -y
npm install vue --save
包.json
{
"name": "samat",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"vue": "^2.6.12"
}
}
然后我创建index.html
和index.js
:
<!DOCTYPE html>
<html>
<head>
<script src="./index.js"></script>
</head>
<body>
<div id="app">
{{ message }}
</div>
</body>
</html>
import Vue from 'vue'
var app = new Vue({
el: '#app',
data: {
message: 'Hello Vue!'
}
})
最后,我运行parcel index.html
,然后localhost:1234
在浏览器中查看但只看到这个:
{{message}}
解决方案
要使用 in-DOM 模板(即<div id="app>{{ message }}</div>
),请导入包含运行时模板编译器的 Vue 的完整构建:
// import Vue from 'vue'
import Vue from 'vue/dist/vue.esm.browser' // full build
推荐阅读
- android - 无法在 Android 上的 WebView 中下载 Blob 文件类型
- excel - 使用VBA查找工作表中有多少非空白行
- assembly - 在 x86_64 程序集中将一个 .data 和一个 .bss 字符串连接在一起
- ios - SpriteKit 中的 init() vs didMove vs sceneDidLoad
- odoo - odoo 中的 stock.pack.operation 和 stock.move 有什么区别?
- mongodb - 在 Mongoose 中按提供的条件数组中的项目顺序对查询结果进行排序
- glsl - 如何绘制由 GLSL 中的几个函数生成的形状?
- xml - DITA XSLT 编写技巧
- ios - IOS Firebase,iOS的什么数据类型相当于“地图”字段??
- hive - 从 hive 表中读取并更新 pyspark 中的同一张表 - 使用检查点