1. Switch between production environment and development environment
Development environment: the development environment is to configure proxyTable in /config/index.js production environment: the agent is invalid after packaging the project, so you need to reconfigure it in the production environment
1. The first method is to configure the. Env file
Reference: cli.vuejs.org/zh/guide/mo… The second way
Step 1: Create different environment js files, and then cross-env to switch config dev.js prod.js dev.jsmodule.exports = {
BASE_URL: "https://test.365msmk.com"
};
prod.js
module.exports = {
BASE_URL: "https://www.365msmk.com"
};
Copy the code
Step 2: Install cross-env and configure the parameters to pass in package.json: NPM install cross-env -d
In the package. The json configuration
"scripts": {
"serve": "cross-env BUILD_ENV=dev vue-cli-service serve"."build": "cross-env BUILD_ENV=prod vue-cli-service build"} Step 3: Modify vue.config.js to add webpack configurationmodule.exports = {
.....
chainWebpack: config= > {
config.plugin("define").tap(args= > {
args[0] ['process.env'].BUILD_ENV = JSON.stringify(process.env.BUILD_ENV);
returnargs; }); }}; Make environment switch in business code// Read BUILD_ENV in the process.env constant object
const envType = process.env.BUILD_ENV;
const urlObj = require(`.. /config/${envType}.js`);
// Create an Axios instance
const service = axios.create({
baseURL: urlObj.BASE_URL + vipUrl
});
Copy the code
Two, filter
The filter
1. Global filters
Function (a,b,c) {function(a,b,c) {
//....
return ...
Copy the code
})
Use:
{{num | filter name (v1, v2)}}
2. Local filter
3. Summary: Filter usage scenario: used to process background data into the final data format displayed by the user
For example: gender, payment status, logistics status, timestamp…
Moment library use
Moment website: momentjs.cn/docs/ Install directive: NPM I moment
Format: moment(timestamp).format(YYYY: MM: month: DD: HH: MM: minute: SS:); HTTP://momentjs.cn/docs/#/displaying/
Copy the code
At present, I am working hard to learn the development environment and production environment, summarize every day, make progress every day, and enter the IT industry leader as soon as possible.