【问题标题】:how can I import a file vuejs component into index.html?如何将文件 vuejs 组件导入 index.html?
【发布时间】:2020-08-18 02:56:08
【问题描述】:

我正在为 VUEjs 使用 CDN,因为我不想使用 webpack 或从服务器渲染。

index.html 和 test-component.vue 在同一个文件夹中

我的 index.html:

<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>VUE</title>

<!-- vuejs -->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>

</head>
<body>

<div id="app">

  <!--HERE I WANT TO USE MY COMPONENT-->
  <comp></comp> 
</div>

<script>

  //TRIED TO IMPORT MY COMPONENT
  import comp from './test-component.vue';

  const app = new Vue({
    el: '#app',
  });

</script>


</body>
</html>

我的 test-component.vue 文件:

<template>
  <h1>im a component</h1>
</template>

<script>
  console.log('testing component');
</script>

【问题讨论】:

  • 如果你在不同的组件文件中分离组件,你将需要使用 vue-loader 为你编译这些 vue 组件的 webpack。在我看来,你必须设置构建过程

标签: javascript html vue.js frontend cdn


【解决方案1】:

显然 .vue 文件不被浏览器原生支持

有两种可能的解决方案:

【讨论】:

  • 但是 .vue sintax 只是 html
  • 不是。它是 的组合
猜你喜欢
  • 2018-07-23
  • 2019-10-13
  • 2021-04-29
  • 2018-06-24
  • 1970-01-01
  • 2021-11-06
  • 2017-09-20
  • 2017-10-08
  • 2019-03-04
相关资源
最近更新 更多