想快速原型開發,使用到生態系統中的vue-cli-service-global
https://cli.vuejs.org/zh/guide/prototyping.html
安裝命令:
npm install -g @vue/cli-service-global
我定義的一個Parent組件,在當前的目錄的components下,內容爲:
<template>
<div>Parent</div>
</template>
我有一個App.vue:
<template>
<div>
<!--3.使用組件 -->
<Parent></Parent>
</div>
</template>
<style scoped>
</style>
<script>
// 1.引入組件(第一步是定義組件,因是外部的,在此直接引入,就可以)
import Parent from "./components/Parent";
export default {
data() {
return {};
},
components: {
Parent //2.註冊組件
}
};
</script>
Vue-cli中說要這麼使用:
Usage: serve [options] [entry]
在開發環境模式下零配置爲 .js 或 .vue 文件啓動一個服務器
Options:
-o, --open 打開瀏覽器
-c, --copy 將本地 URL 複製到剪切板
-h, --help 輸出用法信息
所以我想執行這個App.vue,直接執行命令
vue serve App.vue
不生效,命令行沒有任何效果。
這是因爲,需要重新安裝cli命令工具:
npm install -g @vue/cli
用vue serve命令要全局安裝:
npm install -g @vue/cli-service-global
重新運行vue serve App.vue
,再執行,就沒有問題啦。