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 preload
    config.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#L171
        fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
        include: 'initial'
      }
    ])
 
    // when there are many pages, it will cause too many meaningless requests
    config.plugins.delete('prefetch')
 
    // set svg-sprite-loader
    config.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 package
                  priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
                  test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
                },
                commons: {
                  name: 'chunk-commons',
                  test: resolve('src/components'), // can customize your rules
                  minChunks: 3, //  minimum common number
                  priority: 5,
                  reuseExistingChunk: true
                }
              }
            })
          // https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
          config.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 debug
    Message({
      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.mfbz.cn/a/114069.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

人工智能基础_机器学习013_三种梯度下降对比_线性回归梯度下降更新公式_对梯度下降函数求偏导数_得到---人工智能工作笔记0053

这里批量梯度下降,就是用准备的所有样本数据进行梯度下降计算. 然后小批量梯度下降就是使用比如我一共有500个样本,那么我从中拿出50个样本进行梯度下降计算. 然后随机梯度下降,更厉害, 从一共有500个样本中,随机的取一个样本进行梯度下降计算, 首先我们看批量梯度下降,使用…

【Linux学习笔记】进程概念(中)

1. 操作系统的进程状态2. Linux操作系统的进程状态3. 僵尸进程4. 孤儿进程5. 进程优先级5.1. 优先级是什么和为什么要有优先级5.2. Linux中的进程优先级 6. 进程切换7. 环境变量7.1. 环境变量的认识7.2. 环境变量相关的命令7.3. 环境变量和本地变量7.4. 命令行参数7.5. 获取环境…

使用ssl_certificate_by_lua指令动态加载证书

1、下载 OpenResty - 下载 根据自己系统选择下载&#xff0c;我的是64位 2、解压到目录 3、启动openresty 进入解压后的目录&#xff0c;执行nginx.exe 浏览器输入 http://localhost 查看是否正常。显示以下画面就表示没有问题。 接下来可以开始准备动态安装证书 4、使用o…

渗透测试工具(AntSword)

软件安装 蚁剑渗透测试工具分为AntSword-Loader和antSword两部分 文件下载&#xff1a; AntSword-Loader下载地址&#xff1a;GitHub - AntSwordProject/AntSword-Loader: AntSword 加载器 antSword下载地址&#xff1a;Releases AntSwordProject/antSword GitHub 使用&a…

NLP之LSTM与BiLSTM

文章目录 代码展示代码解读双向LSTM介绍&#xff08;BiLSTM&#xff09; 代码展示 import pandas as pd import tensorflow as tf tf.random.set_seed(1) df pd.read_csv("../data/Clothing Reviews.csv") print(df.info())df[Review Text] df[Review Text].astyp…

Django实战项目-学习任务系统-自定义URL拦截器

接着上期代码框架&#xff0c;6个主要功能基本实现&#xff0c;剩下的就是细节点的完善优化了。 首先增加URL拦截器&#xff0c;你不会希望没有登录用户就可以进入用户主页各种功能的&#xff0c;所以增加URL拦截器可以解决这个问题。 Django框架本身也有URL拦截器&#xff0…

非递归(迭代)遍历二叉树

前言 在树结构中我们经常使用递归算法&#xff0c;但是递归本身的特质会带来很多疑难痛点&#xff0c;比如递归过深导致爆栈&#xff0c;或者是逻辑复杂... 本文将以树的前序遍历为例&#xff0c;浅析迭代算法如何模拟递归过程。 思路 我们先来看看这个算法的具体思想。 在递…

泛微e-office系统存在SQL注入漏洞

泛微e-office系统存在SQL注入漏洞 一、泛微简介二、漏洞描述三、影响版本四、fofa查询语句五、漏洞复现 免责声明&#xff1a;请勿利用文章内的相关技术从事非法测试&#xff0c;由于传播、利用此文所提供的信息或者工具而造成的任何直接或者间接的后果及损失&#xff0c;均由使…

【算能】stream在docker的环境下编译报错

错误问题一&#xff1a; /workspace/sophon-stream/element/multimedia/encode/../../../3rdparty/websocketpp/websocketpp/common/asio.hpp:56:14: fatal error: boost/version.hpp: No such file or directory 56 | #include <boost/version.hpp> 解决方法&a…

rwkv模型lora微调之accelerate和deepspeed训练加速

目录 一、rwkv模型简介 二、lora原理简介 三、rwkv-lora微调 1、数据整理 2、环境搭建 a、Dockerfile编写 b、制造镜像 c、容器启动 3、训练代码修改 四、模型推理 1、模型推理 2、lora权重合并 3、推理web服务 五、总结 由于业务采用的ChatGLM模型推理成本太大了…

软件测试---边界值分析(功能测试)

能对限定边界规则设计测试点---边界值分析 选取正好等于、刚好大于、刚好小于边界的值作为测试数据 上点: 边界上的点 (正好等于)&#xff1b;必选(不考虑区开闭) 内点: 范围内的点 (区间范围内的数据)&#xff1b;必选(建议选择中间范围) 离点: 距离上点最近的点 (刚好…

linux下mysql-8.2.0集群部署(python版本要在2.7以上)

目录 一、三台主机准备工作 1、mysql官方下载地址&#xff1a;https://dev.mysql.com/downloads/ 2、修改/etc/hosts 3、关闭防火墙 二、三台主机安装mysql-8.2.0 1、解压 2、下载相应配置 3、初始化mysql&#xff0c;启动myslq&#xff0c;设置开机自启 4、查看初始密…

代码训练营第59天:动态规划part17|leetcode647回文子串|leetcode516最长回文子序列

leetcode647&#xff1a;回文子串 文章讲解&#xff1a;leetcode647 leetcode516&#xff1a;最长回文子序列 文章讲解&#xff1a;leetcode516 DP总结&#xff1a;动态规划总结 目录 1&#xff0c;leeetcode647 回文子串。 2&#xff0c;leetcode516 最长回文子串&#xff1…

Agent 应用于提示工程

如果Agent模仿了人类在现实世界中的操作方式&#xff0c;那么&#xff0c;能否应用于提示工程即Prompt Engingeering 呢&#xff1f; 从LLM到Prompt Engineering 大型语言模型(LLM)是一种基于Transformer的模型&#xff0c;已经在一个巨大的语料库或文本数据集上进行了训练&…

Docker(1)

文章目录 Docker物理机部署的缺点虚拟机Docker 与虚拟机的区别Docker 的优势 Docker 概念安装 DockerDocker 架构镜像加速Docker 命令进程服务相关命令 镜像相关文件命令容器相关的命令 镜像加载的原理UnionFS(联合文件系统)docker 镜像加载原理 容器的数据卷数据卷概念配置数据…

一座 “数智桥梁”,华为助力“天堑变通途”

《水调歌头游泳》中的一句话&#xff0c;“一桥飞架南北&#xff0c;天堑变通途”&#xff0c;广为人们所熟知&#xff0c;其中展现出的&#xff0c;是中国人对美好出行的无限向往。 天堑变通途从来不易。 中国是当今世界上交通运输最繁忙、最快捷的国家之一&#xff0c;交通行…

2024上海国际人工智能展(CSITF)以“技术,让生活更精彩”为核心理念,以“创新驱动发展,保护知识产权,促进技术贸易”为主题

2024上海国际人工智能展&#xff08;CSITF&#xff09; China&#xff08;Shanghai&#xff09;International Technology Fair 时间:2024年6月12-14日 地点:上海世博展览馆 主办单位 中华人民共和国商务部 中华人民共和国科学技术部 中华人民共和国国家知识产权局 上海市…

C#,数值计算——求解一组m维线性Volterra方程组的计算方法与源程序

1 文本格式 using System; namespace Legalsoft.Truffer { /// <summary> /// 求解一组m维线性Volterra方程组 /// Solves a set of m linear Volterra equations of the second kind using the /// extended trapezoidal rule.On input, t0 is the st…

Git 标签(Tag)实战:打标签和删除标签的步骤指南

目录 前言使用 Git 打本地和远程标签&#xff08;Tag&#xff09;删除本地和远程 Git 标签&#xff08;Tag&#xff09;开源项目标签&#xff08;Tag&#xff09;实战打标签删除标签 结语开源微服务商城项目前后端分离项目 前言 在开源项目中&#xff0c;版本控制是至关重要的…

python脚本监听域名证书过期时间,并将通知消息到钉钉

版本一&#xff1a; 执行脚本带上 --dingtalk-webhook和–domains后指定钉钉token和域名 python3 ssl_spirtime.py --dingtalk-webhook https://oapi.dingtalk.com/robot/send?access_tokenavd345324 --domains www.abc1.com www.abc2.com www.abc3.com脚本如下 #!/usr/bin…