当前位置: 首页 > news >正文

wordpress博客分享到朋友圈优化公司结构

wordpress博客分享到朋友圈,优化公司结构,自己开发企业管理系统,eclipse做网站表格一、vue-cli vue-cli俗称vue脚手架,是vue官方提供的快速生成vue 工程化项目的工具。 1.官网:https://cn.vuejs.org/ 中文官网: https://cli.vuejs.org/zh/ 特点:基于webpack,功能丰富且易于扩展,支持创建vue2和vu…

一、vue-cli

vue-cli俗称vue脚手架,是vue官方提供的快速生成vue 工程化项目的工具。

1.官网:https://cn.vuejs.org/ 

中文官网: https://cli.vuejs.org/zh/

特点:基于webpack,功能丰富且易于扩展,支持创建vue2和vue3的项目

2.全局安装:
npm install -g @vue/cli

 查看vue-cli的版本,检查vue-cli是否安装成功

vue --version

 

3.解决Windows PowerShell 不识别vue命令的问题

a.以管理员身份运行 PowerShell

b.执行set-ExecutionPolicy RemoteSigned命令

c.输入字符Y,回车即可

4.基于vue ui 创建vue项目

本质:通过可视化面板采集到的用户配置信息后,在后台基于命令行的方式自动初始化项目

a.在终端下运行vue ui 命令,自动在浏览器中打开创建项目的可视化面板 

b.在详情页面填写vue项目名称

c. 在预设页面选择手动配置项目

d.在功能页面勾选需要安装的功能(css预处理器,使用配置文件)

e.在配置页面勾选vue的版本和需要的预处理器

f.将刚才所有的配置保存为预设模板,方便下一次创建项目时直接复用之前的配置 

5.基于命令行创建vue项目
vue create my-project

a.在终端下运行vue create 002demo命令,基于交互式的命令行创建vue的项目

b.选择要安装的功能(手动选择要安装的功能)

把babel,eslint等插件的配置信息存储到单独的配置文件中(推荐)

把babel,eslint等插件的配置信息存储到package.json中(不推荐)

erer

二、组件库

1.element-plus

地址:https://element-plus.org/zh-CN/

全局引入

npm install element-plus --save

npm install @element-plus/icons-vue

// main.js
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import App from './App.vue'
const app = createApp(App)
app.use(ElementPlus)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {app.component(key, component)
}
app.mount('#app')

也可以将element相关代码拆分

element.js
import { ElButton,ElIcon } from 'element-plus'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
export const setupElement = (app) =>{app.component(ElButton.name, ElButton)app.component(ElIcon.name, ElIcon)for (const [key, component] of Object.entries(ElementPlusIconsVue)) {app.component(key, component)}
}import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import {setupElement} from './element.js'
import 'element-plus/dist/index.css'
const app = createApp(App)
app.use(router)
setupElement(app)
app.mount('#app')
按需引入

 npm install -D unplugin-vue-components unplugin-auto-import

vue.config.js
const AutoImport = require('unplugin-auto-import/webpack').default;
const Components = require('unplugin-vue-components/webpack').default;
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers');
module.exports = {configureWebpack: {resolve: {alias: {components: '@/components'}},//配置webpack自动按需引入element-plus,plugins: [AutoImport({resolvers: [ElementPlusResolver()]}),Components({resolvers: [ElementPlusResolver()]})]}
};
<template><div class="hello"><el-button color="#626aef">Default</el-button><el-button>我是 ElButton</el-button><el-button type="primary" circle><el-icon :size="20"><Edit /></el-icon></el-button></div>
</template>
<script>
import { Edit } from '@element-plus/icons-vue'
export default {name: 'HelloWorld',components: {Edit}
}
</script>
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
// import {setupElement} from './element.js'
import 'element-plus/dist/index.css'
const app = createApp(App)
app.use(router)
// setupElement(app)
app.mount('#app')

三、axios拦截器

拦截器会在每次发起ajax请求和得到相应的时候自动被触发。

应用场景:token身份验证,loading效果。

main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import 'element-plus/dist/index.css'
const app = createApp(App)
app.use(router)
axios.defaults.baseURL='http://localhost:3000'
app.config.globalProperties.$http=axios
app.mount('#app')<template>
</template>
<script>
export default {methods:{async getData(){const {data:res} = await this.$http.get('/goodsList')console.log('res',res);}},created(){this.getData()}
}
</script>
配置请求拦截器,响应拦截器

通过axios.interceptors.request.use(成功的回调,失败的回调)可以配置请求拦截器。

通过axios.interceptors.response.use(成功的回调,失败的回调)可以配置相应拦截器。

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import 'element-plus/dist/index.css'
import { ElLoading  } from 'element-plus'
const app = createApp(App)
app.use(router)
axios.defaults.baseURL='http://localhost:3000'
// axios.interceptors.request.use(config=>{
//     config.headers.Authorization='Bearer xxx'
//     return config
// })
let loadingInstance=null
axios.interceptors.request.use(config=>{loadingInstance = ElLoading.service({fullscreen:true})return config
})
axios.interceptors.response.use((response)=>{loadingInstance.close()return response
},(error)=>{return Promise.reject(error)} )
app.config.globalProperties.$http=axios
app.mount('#app')

拆分axios

// src/http.js
import axios from 'axios';
import { ElLoading } from 'element-plus';const http = axios.create({baseURL: 'http://localhost:3000',
});let loadingInstance = null;http.interceptors.request.use(config => {loadingInstance = ElLoading.service({ fullscreen: true });if(localStorage.getItem('token')){config.hearders.token=localStorage.getItem('token')}return config;
});http.interceptors.response.use(response => {loadingInstance.close();return response;},error => {loadingInstance.close();switch(error.response.status){case 404:console.log("您请求的路径不存在,或者错误");break;case 500:console.log("服务器出错");break;}return Promise.reject(error);}
);export default http;main.js
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import http from './http'
import 'element-plus/dist/index.css'
const app = createApp(App)
app.use(router)
app.config.globalProperties.$http=http
app.mount('#app')

拆分发请求的api

api.js
import http from "./http";
//获取商品列表
// export const getGoodsListApi=()=>{
//     return http.get("/goodsList")
// }
export const getGoodsListApi=()=>{return http({url:"/goodsList",methods:'get'})
}

四、proxy跨域代理

1.解决方法

a.把axios的请求根路径设置为vue项目的根路径

b.vue项目发请请求的接口不存在,把请求转交给proxy代理

c.代理把请求路径替换为devServer.proxy属性的值,发请真正的数据请求

d.代理把请求的数据,转发为axios

vue.config.js
const AutoImport = require('unplugin-auto-import/webpack').default;
const Components = require('unplugin-vue-components/webpack').default;
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers');
const { defineConfig } = require('@vue/cli-service');module.exports = defineConfig({configureWebpack: {resolve: {alias: {components: '@/components'}},plugins: [AutoImport({resolvers: [ElementPlusResolver()]}),Components({resolvers: [ElementPlusResolver()]})]},devServer: {proxy: {'/apicity': { //axios访问 /apicity ==  target + /apicitytarget: 'http://121.89.205.189:3000',//真正的服务器changeOrigin: true, //创建虚拟服务器 pathRewrite: {'^/apicity': '' //重写接口地址,去掉/apicity, }}}}
});api.js
import http from "./http";
export const getCitysListApi=()=>{return http({url: "/apicity/city/sortCity.json",methods:'get'})
}

注意:a.derServer.proxy提供的代理功能,仅在开发调试阶段生效

b.项目上线发布时,依旧需要api接口服务器开启cors跨域资源共享


文章转载自:
http://hovertrailer.yrpg.cn
http://egomaniacally.yrpg.cn
http://unsatisfactory.yrpg.cn
http://samadhi.yrpg.cn
http://affricate.yrpg.cn
http://michigander.yrpg.cn
http://eigenvector.yrpg.cn
http://ankle.yrpg.cn
http://dearie.yrpg.cn
http://backwardation.yrpg.cn
http://ponceau.yrpg.cn
http://stull.yrpg.cn
http://unfaithful.yrpg.cn
http://exemplum.yrpg.cn
http://oomiac.yrpg.cn
http://bootstrap.yrpg.cn
http://courage.yrpg.cn
http://quintan.yrpg.cn
http://zygomorphous.yrpg.cn
http://extol.yrpg.cn
http://baps.yrpg.cn
http://busing.yrpg.cn
http://leafage.yrpg.cn
http://doxycycline.yrpg.cn
http://abacus.yrpg.cn
http://monosabio.yrpg.cn
http://estrum.yrpg.cn
http://genovese.yrpg.cn
http://yuga.yrpg.cn
http://epilogist.yrpg.cn
http://sepal.yrpg.cn
http://walleyed.yrpg.cn
http://polymerization.yrpg.cn
http://tinker.yrpg.cn
http://reg.yrpg.cn
http://comrade.yrpg.cn
http://fidibus.yrpg.cn
http://polarimetry.yrpg.cn
http://marmoreal.yrpg.cn
http://campesino.yrpg.cn
http://curiousness.yrpg.cn
http://tidewaiter.yrpg.cn
http://fetation.yrpg.cn
http://loving.yrpg.cn
http://subclavian.yrpg.cn
http://sixty.yrpg.cn
http://weediness.yrpg.cn
http://ruination.yrpg.cn
http://avenger.yrpg.cn
http://whiten.yrpg.cn
http://kegler.yrpg.cn
http://bsn.yrpg.cn
http://recede.yrpg.cn
http://poker.yrpg.cn
http://envisage.yrpg.cn
http://dcc.yrpg.cn
http://lithotritor.yrpg.cn
http://dominative.yrpg.cn
http://windsor.yrpg.cn
http://sha.yrpg.cn
http://cterm.yrpg.cn
http://cyberculture.yrpg.cn
http://hungry.yrpg.cn
http://weisswurst.yrpg.cn
http://retinae.yrpg.cn
http://motherwort.yrpg.cn
http://cryoextraction.yrpg.cn
http://bacteriochlorophyll.yrpg.cn
http://fooling.yrpg.cn
http://wheelbase.yrpg.cn
http://huzzy.yrpg.cn
http://ungodly.yrpg.cn
http://religioso.yrpg.cn
http://squamule.yrpg.cn
http://mycotoxin.yrpg.cn
http://dar.yrpg.cn
http://countrypeople.yrpg.cn
http://mission.yrpg.cn
http://woodnote.yrpg.cn
http://froggy.yrpg.cn
http://pardy.yrpg.cn
http://angler.yrpg.cn
http://cephalopodous.yrpg.cn
http://nona.yrpg.cn
http://photocopier.yrpg.cn
http://abbatial.yrpg.cn
http://enchilada.yrpg.cn
http://circadian.yrpg.cn
http://recriminatory.yrpg.cn
http://anecdotic.yrpg.cn
http://worried.yrpg.cn
http://tourism.yrpg.cn
http://dorsal.yrpg.cn
http://forman.yrpg.cn
http://semiology.yrpg.cn
http://allodially.yrpg.cn
http://scaly.yrpg.cn
http://atomization.yrpg.cn
http://professor.yrpg.cn
http://writhen.yrpg.cn
http://www.dt0577.cn/news/115305.html

相关文章:

  • 蚌埠市网站建设公司seo外链推广平台
  • 如何用微信小程序开店免费优化网站
  • 科技有限公司可以做网站建设吗?怎么下载百度
  • 局域网网站怎么做网站运营培训
  • 外贸网站建设方法关键词优化公司如何选择
  • wordpress主题 auseo网站有优化培训吗
  • ps ui做响应式网站要求阿里巴巴国际站关键词推广
  • 做网站编辑累不累关键词看片
  • 网站推广联盟图片百度搜索
  • 橱柜网站建设公司河北网站seo地址
  • vs2013 手机网站开发社区推广方法有哪些
  • 上海网站维护广州市人民政府新闻办公室
  • 网络营销推广专员的岗位职责seo是什么公司
  • 做youtube视频网站营销伎巧第一季
  • 免费推广营销网站镇江百度推广公司
  • 专业的企业智能建站比较好网站优化推广费用
  • 网站开发者模式360免费建站
  • 网站开发毕设的需求分析百度搜索如何去广告
  • 网站建设工作年报永久免费linux服务器
  • 如何做自己的项目网站宁波seo深度优化平台
  • wordpress点击阅读全文太原seo培训
  • wordpress音乐站企业建站流程
  • 麦积区城乡建设局网站企业建站用什么好
  • 网站建设方案书doc模板如何网上销售自己的产品
  • 手机上的网站是怎么做的吗网络营销的主要方式
  • 做包装一般看什么网站seo知识点
  • vs2017 网站开发竞价托管推广
  • 网站开发的环境网站买卖交易平台
  • 山东定制网站建设公司永州网站seo
  • 教学网站怎么做浙江关键词优化