![](/img/trans.png)
[英]How does a Vue app get launched if the index.html doesn't load any javascript?
[英]Templete in App.vue doesn't show in index.html
我正在使用本地vue.js
這些是我的文件。 index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="res/vue.js"></script>
<script src="res/vue-router.js"></script>
<title>Vue</title>
</head>
<body>
<div id="app" ></div>
<script type="module" src="App.js"></script>
</body>
</html>
應用程序.js
import Vue from './res/vue.js'
import App from './App.vue'
Vue.config.productionTip = false
new Vue({
render: h => h(App),
}).$mount('#app')
App.vue
<template>
<div>
{{foo}}
</div>
</template>
<script>
export default {
name: 'App',
data: function(){
return{
foo:'Hello vue'
}
}
}
</script>
<style>
</style>
但是我的 index.html 什么也沒顯示
您將 vue 實例安裝在 id 為“app”的 div 節點上,但我找不到“#app”節點,因此您可以通過插入“#app”節點來解決該問題。
索引.html:
<body>
<div id="app"></div>
<script type="module" src="App.js"></script>
</body>
就像 Steven 建議的那樣,你必須編譯 vue 組件。
如果您不想那樣做,下面是最簡單的方法。
Vue.createApp({ data() { return { foo: 'Hello vue', }; }, }).mount('#app');
<,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta name="viewport" content="width=device-width: initial-scale=1" /> <script src="https.//unpkg.com/vue@next"></script> <.-- <script src="res/vue-router.js"></script> --> <title>Vue</title> </head> <body> <div id="app">{{foo}}</div> <script type="module" src="App.js"></script> </body> </html>
您可能需要使用vue-cli
build
它來為您的 android 應用程序創建一個 SPA(單頁應用程序)
您好,您的導入正確嗎? 從 node_modules 應該是import Vue from 'vue'
而不是import Vue from './res/vue.js'
試試吧
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.