简体   繁体   English

App.vue 中的 Templete 未显示在 index.html 中

[英]Templete in App.vue doesn't show in index.html

I am using local vue.js These are my files.我正在使用本地vue.js这些是我的文件。 index.html 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>

App.js应用程序.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 App.vue

<template>
  <div>
    {{foo}}
  </div>
</template>


<script>
  export default {
    name: 'App',
    data: function(){
      return{
        foo:'Hello vue'
      }
    }
  }
</script>


<style>

</style>

But my index.html shows nothing但是我的 index.html 什么也没显示

You mount your vue instance at the div node which id is "app", but i can't find the "#app" node, so you can resolve that by insert the "#app" node.您将 vue 实例安装在 id 为“app”的 div 节点上,但我找不到“#app”节点,因此您可以通过插入“#app”节点来解决该问题。

index.html:索引.html:

<body>
    <div id="app"></div>
    <script type="module" src="App.js"></script>
</body>

Like the Steven suggested you have to compile vue components.就像 Steven 建议的那样,你必须编译 vue 组件。

If you dont want to do it that way, below is the the easiet way.如果您不想那样做,下面是最简单的方法。

 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>

You probably need to build it with vue-cli to create a SPA(Single page Application) for your android application您可能需要使用vue-cli build它来为您的 android 应用程序创建一个 SPA(单页应用程序)

Hi is your import correct?您好,您的导入正确吗? from node_modules it should be import Vue from 'vue' and not import Vue from './res/vue.js' try it从 node_modules 应该是import Vue from 'vue'而不是import Vue from './res/vue.js'试试吧

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM