国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue(32) : win10創(chuàng)建vue2基礎前端框架

這篇具有很好參考價值的文章主要介紹了vue(32) : win10創(chuàng)建vue2基礎前端框架。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

  • vue2
  • element-ui
  • axios

含接口調(diào)用示例

1.創(chuàng)建vue2項目

開發(fā)工具為HBuilderX 3.7.3

1.1.新建項目

vue(32) : win10創(chuàng)建vue2基礎前端框架,前端,vue.js,前端框架,javascript,vue項目2

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

vue(32) : win10創(chuàng)建vue2基礎前端框架,前端,vue.js,前端框架,javascript,vue項目2

等待創(chuàng)建項目

vue(32) : win10創(chuàng)建vue2基礎前端框架,前端,vue.js,前端框架,javascript,vue項目2

2.安裝element-ui組件

2.1右鍵左下角開始圖標

vue(32) : win10創(chuàng)建vue2基礎前端框架,前端,vue.js,前端框架,javascript,vue項目2

?2.2.cd進入項目目錄,執(zhí)行安裝element-ui

npm i element-ui -S

vue(32) : win10創(chuàng)建vue2基礎前端框架,前端,vue.js,前端框架,javascript,vue項目2

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

vue(32) : win10創(chuàng)建vue2基礎前端框架,前端,vue.js,前端框架,javascript,vue項目2

3.2.項目根目錄創(chuàng)建[vue.config.js]文件, 內(nèi)容如下

'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://127.0.0.1:33001', // 后端地址
        // target: 'localhost:8080/manage', // 原始地址
        changeOrigin: true, // 開啟代理,在本地創(chuàng)建一個虛擬服務端
        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()
  }
}

代理后端配置如下, 三個test改成相同的uri前綴即可, uri該簽注會代理到后端

proxy: {
? ? ? // 代理test開頭的uri
? ? ? '/test': {
? ? ? ? target: 'http://192.168.1.1:8080', // 后端地址
? ? ? ? changeOrigin: true, // 開啟代理,在本地創(chuàng)建一個虛擬服務端
? ? ? ? pathRewrite: {
? ? ? ? ? '^/test': '/test'
? ? ? ? }
? ? ? }
? ? }

?3.3.src下創(chuàng)建util目錄, util文件夾下創(chuàng)建request.js, 內(nèi)容如下

const res = response.data

這個需要根據(jù)后端接口格式修改

/*引入axios*/
import axios from 'axios'
import {
	MessageBox,
	Message
} from 'element-ui'

const request = axios.create({
	baseURL: '', // 基礎路徑,將統(tǒng)一的部分全部封裝
	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.errCode !== 0) {
			Message({
				message: res.errMessage || '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.創(chuàng)建測試調(diào)用http

4.1.src下創(chuàng)建api目錄, api下創(chuàng)建test.js, 內(nèi)容如下

import request from '@/util/request'
 
 
export function test() {
  return request({
    url: '/test/2',
    method: 'get'
  })
}

4.2. App.vue替換

<template>
	<div>
		{{ testData }}
	</div>
</template>

<script>
	import {
		test,
	} from '@/api/test'

	export default {
		name: 'app',
		data() {
			return {
				testData: null
			}
		},
		created() {
			this.t1()
		},
		methods: {
			t1() {
				test().then(response => {
					console.log(response)
					this.testData = response.msg
				})
			}
		}
	}
</script>

<style>
</style>

4.3.后臺接口需要返回以下內(nèi)容

接口地址為 :?http://127.0.0.1:33001/test/2

    @GetMapping("/test/2")
    public Object test2() {
        Map<String, Object> res = new HashMap<>();
        res.put("code", 200);
        res.put("errCode", 0);
        res.put("errMessage", "測試錯誤");
        res.put("msg", "SUCCESS");
        return res;
    }

內(nèi)容如下

{
"msg": "SUCCESS",
"code": 200,
"errCode": 0,
"errMessage": "測試錯誤"
}?

5.啟動

npm run serve

vue(32) : win10創(chuàng)建vue2基礎前端框架,前端,vue.js,前端框架,javascript,vue項目2

6.編譯

npm run build

7.部署

dist里面的文件放到nginx目錄下

nginx.conf添加以下配置

		location /test {
            proxy_pass http://127.0.0.1:33001;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   Host              $http_host;
            proxy_set_header   X-Real-IP         $remote_addr;
        }

可以參考 :VUE(5) : vue-element-admin[5] : 打包及nginx部署_使用nginx部署vue-element-admin項目-CSDN博客文章來源地址http://www.zghlxwxcb.cn/news/detail-738857.html

到了這里,關(guān)于vue(32) : win10創(chuàng)建vue2基礎前端框架的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領支付寶紅包贊助服務器費用

相關(guān)文章

  • web前端框架JS學習之JavaScript類型轉(zhuǎn)換

    web前端框架JS學習之JavaScript類型轉(zhuǎn)換

    vascript有多種數(shù)據(jù)類型,如字符串、數(shù)字、布爾等,可以通過typeof語句來查看變量的數(shù)據(jù)類型。數(shù)據(jù)類型轉(zhuǎn)換就是數(shù)據(jù)類型之間相互轉(zhuǎn)換,比如把數(shù)字轉(zhuǎn)成字符串、把布爾值轉(zhuǎn)成字符串、把字符串轉(zhuǎn)成數(shù)字等,這在工作也是經(jīng)常碰到的。 本期我們就給大家說說web前端框架JS學

    2024年02月10日
    瀏覽(90)
  • 前端學習--vue2--2--vue指令基礎

    前端學習--vue2--2--vue指令基礎

    寫在前面: 前置內(nèi)容 - vue配置 vue指令只的是帶有v-前綴的特殊標簽屬性 插值表達式{{}}是一種vue模板語法。 利用表達式進行差值,渲染到頁面。 表達式可以是被求值的代碼,js會計算 不能用差值表達式的 不存在的數(shù)據(jù) {{data里面不存在的字段 js {{if}} 標簽屬性 span id=“

    2024年02月14日
    瀏覽(28)
  • ? 全面解析若依框架vue2版本(springboot-vue前后分離--前端部分)

    ? 全面解析若依框架vue2版本(springboot-vue前后分離--前端部分)

    一般在vue項目public文件夾下命名為“favicon.ico” ? 處理步驟 第1步:將圖標重命名為“favicon.ico”,并放在項目根目錄 下。 第2步:然后在index.html中引入,title中修改頁面標題。 第3步:修改build文件夾下 webpack .dev.conf.js和webpack.prod.conf.js文件中的內(nèi)容。 第五步:重新已經(jīng)成功

    2024年02月12日
    瀏覽(99)
  • Vue2和Vue3是Vue.js框架的兩個主要版本,它們之間有以下區(qū)別

    性能優(yōu)化:Vue3在內(nèi)部進行了重寫,采用了更高效的虛擬DOM算法,使得渲染速度更快,性能更好。 更小的體積:Vue3的體積比Vue2更小,這意味著更快的下載和加載速度。 Composition API:Vue3引入了Composition API,它是一種新的組合式API,可以更好地組織和重用組件邏輯,使得代碼更

    2024年02月15日
    瀏覽(26)
  • 【前端vue升級】vue2+js+elementUI升級為vue3+ts+elementUI plus

    【前端vue升級】vue2+js+elementUI升級為vue3+ts+elementUI plus

    gogo code 是一個基于 AST (源代碼的抽象語法結(jié)構(gòu)樹狀表現(xiàn)形式)的 JavaScript/Typescript/HTML 代碼轉(zhuǎn)換工具,可以用它來構(gòu)建一個代碼轉(zhuǎn)換程序來幫助自動化完成如框架升級、代碼重構(gòu)、多平臺轉(zhuǎn)換等工作。 當前 GoGoCode 支持解析和操作如下類型的代碼: ○JavaScript(JSX) ○Typescript

    2024年02月12日
    瀏覽(31)
  • 前端2023最全面試題(javaScript、typeScript、vue2、vue3、html、css、uniapp、webpack、vite、react)

    答案:JavaScript中的閉包是一種函數(shù),它有權(quán)訪問其詞法環(huán)境的變量和其它函數(shù)。這意味著,即使其包含它的函數(shù)已經(jīng)執(zhí)行完畢,其詞法環(huán)境仍然存在,因此可以訪問其作用域內(nèi)的變量。 答案:回調(diào)函數(shù)是在某個特定事件之后執(zhí)行的函數(shù)。在JavaScript中,通常使用回調(diào)函數(shù)來處

    2024年02月06日
    瀏覽(35)
  • 【前端】在Vue2中使用Vanta.js炫酷動態(tài)背景(全屏背景)

    【前端】在Vue2中使用Vanta.js炫酷動態(tài)背景(全屏背景)

    官網(wǎng):https://www.vantajs.com/ 由于博主在參考官網(wǎng)及官方GitHub進行應用時遇到一些問題,因此寫了該篇博客,以避免大家因找Bug而浪費時間,方便快速的應用。 注意版本 Vue的版本如下 “vue”: “^2.6.14” 渲染容器 導包 方法 完整代碼: 完整代碼: 參加顏色參數(shù) 如果報錯:‘X

    2024年02月11日
    瀏覽(33)
  • Jeecg開發(fā)框架前端VUE2數(shù)據(jù)頁面與后端數(shù)據(jù)庫交互實現(xiàn)

    Jeecg開發(fā)框架前端VUE2數(shù)據(jù)頁面與后端數(shù)據(jù)庫交互實現(xiàn)

    ? JeecgBoot 是一款基于代碼生成器的 低代碼 開發(fā)平臺,零代碼開發(fā)!采用前后端分離架構(gòu):SpringBoot2.x,Ant DesignVue,Mybatis-plus,Shiro,JWT。強大的代碼生成器讓前后端代碼一鍵生成,無需寫任何代碼! JeecgBoot引領新的開發(fā)模式(Online Coding模式- 代碼生成器模式- 手工MERGE智能開發(fā)

    2024年02月11日
    瀏覽(50)
  • JavaScript 框架比較:Angular、React、Vue.js

    在 Web 開發(fā)領域,JavaScript 提供大量技術(shù)??晒┻x擇。其中最典型的三套組合,分別是 MERN、MEAN 和 MEVN。這些首字母相同的選項各自代表不同的技術(shù)加工具組合。為了在這些技術(shù)棧中做出明智選擇,讓我們先從核心組件聊起,再對各自前端框架(React、Angular 和 Vue)進行簡化比

    2024年01月20日
    瀏覽(36)
  • Rspack 創(chuàng)建 vue2/3 項目接入 antdv(rspack.config.js 配置 less 主題)

    Rspack 創(chuàng)建 vue2/3 項目接入 antdv(rspack.config.js 配置 less 主題)

    Rspack CLI 官方文檔。 rspack.config.js 官方文檔。 創(chuàng)建項目(文檔中還提供了 Rspack 內(nèi)置 monorepo 框架 Nx 的創(chuàng)建方式,根據(jù)需求進行選擇) 創(chuàng)建好項目并運行,目前 Rspack 版本支持的工程模版: 默認創(chuàng)建的 vue 項目為 vue3 : 如果需要其他版本,或其他框架的基礎工程,可到官方提

    2024年02月11日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領取紅包,優(yōu)惠每天領

二維碼1

領取紅包

二維碼2

領紅包