我使用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>
我的测试组件.vue文件:
<template>
<h1>im a component</h1>
</template>
<script>
console.log('testing component');
</script>
显然浏览器本机不支持vue文件
有两种可能的解决方案:
-
使用javascript捆绑程序(如webpack或package(
-
使用http vue加载程序