Article Directory
1. Vue
Basic usage of single file components
Composition structure of single file components:
template
: The template area of the componentscript
: Business logic areastyle
: Style area
<template>
<!-- 这里用于定义Vue组件的模板内容 -->
</template>
<script>
// 这里用于定义Vue组件的业务逻辑
export default {
data: () {
return {
}
}, // 私有数据
methods: {
} // 处理函数
// ... 其它业务逻辑
}
</script>
<style scoped>
/* 这里用于定义组件的样式 */
</style>
2. The loader webpack
of the configuration vue
component
-
Run
npm i vue-loader vue-template-compiler -D
command -
In the
webpack.config.js
configuration file, the addedvue-loader
configuration items are as follows:const VueLoaderPlugin = require('vue-loader/lib/plugin') module.exports = { module: { rules: [ // ... 其它规则 { test: /\.vue$/, loader: 'vue-loader' } ] }, plugins: [ // ... 其它插件 new VueLoaderPlugin() // 请确保引入这个插件! ] }
3. webpack
Use in the projectvue
-
Run
npm i vue –S
installvue
-
In the
src -> index.js
entry file,import Vue from 'vue'
import thevue
constructor by -
Create
vue
an instance object and specify theel
area to be controlled -
render
Render theApp
root component through a function// 1. 导入 Vue 构造函数 import Vue from 'vue' // 2. 导入 App 根组件 import App from './components/App.vue' const vm = new Vue({ // 3. 指定 vm 实例要控制的页面区域 el: '#app', // 4. 通过 render 函数,把指定的组件渲染到 el 区域中 render: h => h(App) })
4. webpack
Package release
Before going online, webpack
the application needs to be packaged as a whole, and the package.json
packaging command can be configured through the file:
// 在package.json文件中配置 webpack 打包命令
// 该命令默认加载项目根目录中的 webpack.config.js 配置文件
"scripts": {
// 用于打包的命令
"build": "webpack -p",
// 用于开发调试的命令
"dev": "webpack-dev-server --open --host 127.0.0.1 --port 3000",
},