vue(32) : win10创建vue2基础前端框架

  • vue2
  • element-ui
  • axios

1.创建vue2项目

开发工具为HBuilderX 3.7.3

1.1.新建项目

1.2.普通项目-vue项目(2.6.10)

等待创建项目

2.安装element-ui组件

2.1右键左下角开始图标

 2.2.cd进入项目目录,执行安装element-ui

npm i element-ui -S

 

2.3.main.js引入配置

import {Pagination,Dialog,Autocomplete,Dropdown,DropdownMenu,DropdownItem,Menu,Submenu,MenuItem,MenuItemGroup,Input,InputNumber,Radio,RadioGroup,RadioButton,Checkbox,CheckboxButton,CheckboxGroup,Switch,Select,Option,OptionGroup,Button,ButtonGroup,Table,TableColumn,DatePicker,TimeSelect,TimePicker,Popover,Tooltip,Breadcrumb,BreadcrumbItem,Form,FormItem,Tabs,TabPane,Tag,Tree,Alert,Slider,Icon,Row,Col,Upload,Progress,Spinner,Badge,Card,Rate,Steps,Step,Carousel,CarouselItem,Collapse,CollapseItem,Cascader,ColorPicker,Transfer,Container,Header,Aside,Main,Footer,Timeline,TimelineItem,Link,Divider,Image,Calendar,Backtop,PageHeader,CascaderPanel,Loading,MessageBox,Message,Notification
} from 'element-ui';Vue.use(Pagination);
Vue.use(Dialog);
Vue.use(Autocomplete);
Vue.use(Dropdown);
Vue.use(DropdownMenu);
Vue.use(DropdownItem);
Vue.use(Menu);
Vue.use(Submenu);
Vue.use(MenuItem);
Vue.use(MenuItemGroup);
Vue.use(Input);
Vue.use(InputNumber);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(RadioButton);
Vue.use(Checkbox);
Vue.use(CheckboxButton);
Vue.use(CheckboxGroup);
Vue.use(Switch);
Vue.use(Select);
Vue.use(Option);
Vue.use(OptionGroup);
Vue.use(Button);
Vue.use(ButtonGroup);
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(DatePicker);
Vue.use(TimeSelect);
Vue.use(TimePicker);
Vue.use(Popover);
Vue.use(Tooltip);
Vue.use(Breadcrumb);
Vue.use(BreadcrumbItem);
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Tabs);
Vue.use(TabPane);
Vue.use(Tag);
Vue.use(Tree);
Vue.use(Alert);
Vue.use(Slider);
Vue.use(Icon);
Vue.use(Row);
Vue.use(Col);
Vue.use(Upload);
Vue.use(Progress);
Vue.use(Spinner);
Vue.use(Badge);
Vue.use(Card);
Vue.use(Rate);
Vue.use(Steps);
Vue.use(Step);
Vue.use(Carousel);
Vue.use(CarouselItem);
Vue.use(Collapse);
Vue.use(CollapseItem);
Vue.use(Cascader);
Vue.use(ColorPicker);
Vue.use(Transfer);
Vue.use(Container);
Vue.use(Header);
Vue.use(Aside);
Vue.use(Main);
Vue.use(Footer);
Vue.use(Timeline);
Vue.use(TimelineItem);
Vue.use(Link);
Vue.use(Divider);
Vue.use(Image);
Vue.use(Calendar);
Vue.use(Backtop);
Vue.use(PageHeader);
Vue.use(CascaderPanel);Vue.use(Loading.directive);import axios from 'axios';Vue.prototype.$loading = Loading.service;
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = MessageBox.alert;
Vue.prototype.$confirm = MessageBox.confirm;
Vue.prototype.$prompt = MessageBox.prompt;
Vue.prototype.$notify = Notification;
Vue.prototype.$message = Message;
import 'element-ui/lib/theme-chalk/index.css';

3.安装axios

3.1.npm安装axios

npm install --save axios

3.2.项目根目录创建[vue.config.js]文件, 内容如下

'use strict'
const path = require('path')function resolve(dir) {return path.join(__dirname, dir)
}const port = process.env.port || process.env.npm_config_port || 9527 // dev port
const name =  '测试' // page title// All configuration item explanations can be find in https://cli.vuejs.org/config/
module.exports = {/*** You will need to set publicPath if you plan to deploy your site under a sub path,* for example GitHub Pages. If you plan to deploy your site to https://foo.github.io/bar/,* then publicPath should be set to "/bar/".* In most cases please use '/' !!!* Detail: https://cli.vuejs.org/config/#publicpath*/publicPath: '/',outputDir: 'dist',assetsDir: 'static',lintOnSave: process.env.NODE_ENV === 'development',productionSourceMap: false,devServer: {port: port,open: true,overlay: {warnings: false,errors: true},proxy: {// 代理test开头的uri'/test': {target: 'http://192.168.1.1:8080', // 后端地址// target: 'localhost:8080/manage', // 原始地址changeOrigin: true, // 开启代理,在本地创建一个虚拟服务端pathRewrite: {'^/test': '/test'}}}//before: require('./mock/mock-server.js')},configureWebpack: {// provide the app's title in webpack's name field, so that// it can be accessed in index.html to inject the correct title.name: name,resolve: {alias: {'@': resolve('src')}}},chainWebpack(config) {// it can improve the speed of the first screen, it is recommended to turn on preload// it can improve the speed of the first screen, it is recommended to turn on preloadconfig.plugin('preload').tap(() => [{rel: 'preload',// to ignore runtime.js// https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],include: 'initial'}])// when there are many pages, it will cause too many meaningless requestsconfig.plugins.delete('prefetch')// set svg-sprite-loaderconfig.module.rule('svg').exclude.add(resolve('src/icons')).end()config.module.rule('icons').test(/\.svg$/).include.add(resolve('src/icons')).end().use('svg-sprite-loader').loader('svg-sprite-loader').options({symbolId: 'icon-[name]'}).end()config.when(process.env.NODE_ENV !== 'development',config => {config.plugin('ScriptExtHtmlWebpackPlugin').after('html').use('script-ext-html-webpack-plugin', [{// `runtime` must same as runtimeChunk name. default is `runtime`inline: /runtime\..*\.js$/}]).end()config.optimization.splitChunks({chunks: 'all',cacheGroups: {libs: {name: 'chunk-libs',test: /[\\/]node_modules[\\/]/,priority: 10,chunks: 'initial' // only package third parties that are initially dependent},elementUI: {name: 'chunk-elementUI', // split elementUI into a single packagepriority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or apptest: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm},commons: {name: 'chunk-commons',test: resolve('src/components'), // can customize your rulesminChunks: 3, //  minimum common numberpriority: 5,reuseExistingChunk: true}}})// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunkconfig.optimization.runtimeChunk('single')})}
}

代理后端配置如下, 三个test改成相同的uri前缀即可, uri该签注会代理到后端

proxy: {
      // 代理test开头的uri
      '/test': {
        target: 'http://192.168.1.1:8080', // 后端地址
        changeOrigin: true, // 开启代理,在本地创建一个虚拟服务端
        pathRewrite: {
          '^/test': '/test'
        }
      }
    }

 3.3.src下创建util目录, util文件夹下创建request.js, 内容如下

const res = response.data

这个需要根据后端接口格式修改

/*引入axios*/
import axios from 'axios'
import { MessageBox, Message } from 'element-ui'const request = axios.create({baseURL: '', // 基础路径,将统一的部分全部封装withCredentials: true // 表示请求可以携带cookie
})axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded'// response interceptor
request.interceptors.response.use(/*** If you want to get http information such as headers or status* Please return  response => response*//*** Determine the request status by custom code* Here is just an example* You can also judge the status by HTTP Status Code*/response => {const res = response.data// if the custom code is not 20000, it is judged as an error.if (res.code !== '0') {Message({message: res.message || 'Error',type: 'error',duration: 3 * 1000})// return Promise.reject(new Error(res.message || 'Error'))return null} else {return res}},error => {console.log('err' + error) // for debugMessage({message: error.message,type: 'error',duration: 5 * 1000})return Promise.reject(error)}
)//前端采用export.default,在写后端代码时用module.export
export default request

4.创建测试调用http

4.1.src下创建api目录, api下创建test.js, 内容如下

import request from '@/util/request'export function add(data) {return request({url: '/my-boke',headers: { 'Content-Type': 'application/json' },method: 'post',data})
}export function update(data) {return request({url: '/my-boke',headers: { 'Content-Type': 'application/json' },method: 'put',data})
}export function del(data) {return request({url: '/my-boke',method: 'delete',params: data})
}export function env() {return request({url: '/fsa/env',method: 'get'})
}

4.2. vue.js调用http

<template></template><script>import {add,update,del,env} from '@/api/fsa'export default {name: 'app',data() {return {}},created() {this.t1()},methods: {t1() {env().then(response => {console.log(response)})}}}
</script><style>#app {font-family: 'Avenir', Helvetica, Arial, sans-serif;-webkit-font-smoothing: antialiased;-moz-osx-font-smoothing: grayscale;text-align: center;color: #2c3e50;margin-top: 60px;}
</style>

5.启动

npm run serve

6.编译

报错, 待解决

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/158362.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【蓝桥杯选拔赛真题47】python核酸日期 青少年组蓝桥杯python 选拔赛STEMA比赛真题解析

目录 python核酸日期打分 一、题目要求 1、编程实现 2、输入输出

【Jmeter】自动化测试实施

前言&#xff1a; Jmeter是目前最流行的一种测试工具&#xff0c;基于此工具我们搭建了一整套的自动化方案&#xff0c;包括了脚本添加配置、本地配置和运行、服务器配置等内容&#xff0c;完成了自动化测试闭环&#xff0c;通过这种快捷简便高效的方式&#xff0c;希望可以解…

bean product not found within scope之解决方法

错误原因&#xff1a; 获取bean中的商品信息时报错 解决方法&#xff1a; 修改为下面代码即可&#xff1a; <jsp:useBean id"product" class"com.model.Product" scope"session"></jsp:useBean>

(免费领源码)Java#MYSQL在线学习平台09650-计算机毕业设计项目选题推荐

目 录 摘要 1 绪论 1.1 选题背景及意义 1.2国内外现状分析 1.3论文结构与章节安排 2 在线学习平台系统分析 2.1 可行性分析 2.2 系统业务流程分析 2.3 系统功能分析 2.3.1 功能性分析 2.3.2 非功能性分析 2.4 系统用例分析 2.5本章小结 3 在线学习平台总体设计 …

顺序表(2)

目录 Test.c主函数 test5 test6 test7 菜单 Test.c总代码 SeqList.h头文件&函数声明 头文件 函数声明 SeqList.h总代码 SeqList.c函数实现 查找SeqListFind 某位置插入SeqListInsert 某位置删除SeqListErase SeqList.c总代码 顺序表的问题及其思考 多文件…

[双指针] (四) LeetCode 18.四数之和

[双指针] (四) LeetCode 18.四数之和 文章目录 [双指针] (四) LeetCode 18.四数之和题目解析解题思路代码实现总结 18. 四数之和 题目解析 (1) 从一个数组中找一个目标值target (2) target nums[a] nums[b] nums[c] nums[d] 解题思路 和上一道题三数之和一样, 我们把四…

Linux的常见指令(一)

目录 一、文件 二、常见指令 1、pwd 2、ls 1、ls -a 2、ls -l 3、ls -i ​编辑 3、touch 4、mkdir 5、cd 6、rmdir 和 rm 7、man 8、cp 一、文件 目录和文件是在磁盘上建立的&#xff0c;空文件是在磁盘上占用空间的&#xff08;文件包括文件内容和文件的各种属…

安全与HTTP协议:为何明文传输数据成为争议焦点?

&#x1f3ac; 江城开朗的豌豆&#xff1a;个人主页 &#x1f525; 个人专栏 :《 VUE 》 《 javaScript 》 &#x1f4dd; 个人网站 :《 江城开朗的豌豆&#x1fadb; 》 ⛺️ 生活的理想&#xff0c;就是为了理想的生活 ! 目录 ⭐ 专栏简介 &#x1f4d8; 文章引言 一、H…

四旋翼无人机PID控制Simulink仿真

底部有完整文件地址 整体采用内外环方式对四旋翼的位置和姿态进行控制 Simulink整体模型图 Matlab版本:R2022a 姿态控制效果 滚转角 ϕ \phi ϕ: 俯仰角 θ \theta

软考之软件工程基础理论知识

软件工程基础 软件开发方法 结构化方法 将整个系统的开发过程分为若干阶段&#xff0c;然后依次进行&#xff0c;前一阶段是后一阶段的工作依据按顺序完成。应用最广泛。特点是注重开发过程的整体性和全局性。缺点是开发周期长文档设计说明繁琐&#xff0c;工作效率低开发前要…

社区论坛在线交流网站系统源码+SEO优化 带前后端完整搭建教程

大家好&#xff0c;今天罗峰来给大家分享一款社区论坛在线交流网站系统源码。社区论坛在线交流在当下时时代还是很火的。现在人们对于在线交流和互动的需求不断增加。社区论坛作为一种传统的在线交流方式&#xff0c;仍然有着广泛的市场需求和用户群体。然而&#xff0c;现有的…

笔记:IDEA如何修改代码后,不重启服务器局部更新资源

前言 平常用IDEA开发网页写调样式和测功能最讨厌改一丁点东西就要重启整个服务器&#xff0c;所以本文主要就是解决此问题从而提高开发效率&#xff0c;避免浪费过多时间。 具体步骤 1、打开设置框 2、先新增exploded结尾的&#xff0c;并apply应用&#xff0c;把没有结尾的…