Vue.component
来定义全局组件的缺点:javascript
因此有了文件扩展名为 .vue
的 single-file components
(单文件组件),例子:css
<template> <input type="text" class="input" :value="value" v-on="listeners" > </template> <script> export default { props: { value: { type: String, default: '', } }, computed: { listeners () { return { // Pass all component listeners directly to input ...this.$listeners, // Override input listener to work with v-model input: event => this.$emit('input', event.target.value) } } } } </script> <style lang="scss" scoped> @import '../variables.scss'; .input { width: 100%; padding: 8px 10px; border: 1px solid $vue-blue; } </style>
每个单文件的基本组成结构都包含:template
,script
,style
三个部分。vue
好处:java
这是vue官方提供的脚手架工具webpack
npm install -g @vue/cli
or yarn global add @vue/cli
npm run serve
tips:vscode里安装插件vetur和eslint,*.vue单文件里输入scaffold
会提示一键生成template
,script
,style
三个部分。web
基础篇的官方文档基本撸完了,后续的学习将经过《极客时间_vue开发实战》进行vue-cli