日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 前端技术 > vue >内容正文

vue

vue常用手册

發(fā)布時(shí)間:2024/4/17 vue 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 vue常用手册 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.搭建vue的開(kāi)發(fā)環(huán)境:

1.必須要安裝node.js

2.安裝vue的腳手架工具 官方命令行工具

npm install --global vue-cli

3.新建項(xiàng)目

vue init webpack-simple gw

然后一直回車,新建完成后,cd到gw目錄下,執(zhí)行

cnpm install

4.運(yùn)行項(xiàng)目

npm run dev

運(yùn)行成功后,可以通過(guò)訪問(wèn)

http://localhost:8080/

2.vue路由

vue路由的意思就是不用手動(dòng)掛載組件,實(shí)現(xiàn)動(dòng)態(tài)掛載的方式

1.基礎(chǔ)路由

? 1. 安裝vue-router

cnpm install vue-router --save

2.在src/main.js中

import Vue from 'vue' import App from './App.vue'import VueRouter from 'vue-router'; Vue.use(VueRouter);//1.創(chuàng)建組件 import Home from './components/Home.vue'; import New from './components/New.vue';//2.配置路由 const routes=[{path:'/home',component:Home},{path:'/news',component:New},{path:'*',redirect:'/home'} ]//3.實(shí)例化VueRouter const router=new VueRouter({routes })//4.掛載路由 new Vue({el: '#app',router,render: h => h(App) })//5.在根組件App.vue的模板中,放入<router-view></router-view>

?

3.在src/App.vue中

<template><div id="app"><router-view></router-view></div> </template><script> export default {name: 'app',data () {return {msg:'你好'}} } </script> <style> </style>

4.重新運(yùn)行項(xiàng)目,訪問(wèn):

http://localhost:8080/#/home http://localhost:8080/#/news

即可看到兩個(gè)組件被掛載了。

2.路由跳轉(zhuǎn)

1.通過(guò)標(biāo)簽跳轉(zhuǎn)

1.在src/App.vue的模板中加入router-link

<template><div id="app"><router-link to="/home">首頁(yè)</router-link><router-link to="/news">新聞</router-link><hr><router-view></router-view></div> </template><script> export default {name: 'app',data () {return {msg:'你好'}} } </script> <style> </style>

?2.通過(guò)js跳轉(zhuǎn)

1.在src/components/Home.vue中

<template><div><h2>這是一個(gè)首頁(yè)組件</h2><v-header></v-header><button @click="goNews()">通過(guò)js跳轉(zhuǎn)到新聞頁(yè)面</button></div> </template> <script> export default {methods:{goNews(){this.$router.push({path:'/news'})}} } </script> <style></style>

3.父子路由

1.在src/components目錄下新建User.vue文件,同時(shí)再新建User目錄,在User目錄下新建UserAdd.vue和UserList.vue兩個(gè)文件

User.vue

<template><div id="user"><div class="user"><div class="left"><ul><li><router-link to="/user/useradd">增加用戶</router-link></li><li><router-link to="/user/userlist">用戶列表</router-link></li></ul></div><div class="right"><router-view></router-view></div></div></div> </template> <script> export default {} </script> <style lang="scss" scoped>.user{display: flex;.left{width: 200px;min-height: 400px;border-right: 1px solid #eee}.right{flex: 1;}} </style>

UserAdd.vue

<template><div id="adduser">用戶增加</div> </template>

UserList.vue

<template><div id="userlist">用戶列表</div> </template>

3.在src/main.js中

import Vue from 'vue' import App from './App.vue'import VueRouter from 'vue-router'; Vue.use(VueRouter);//1.創(chuàng)建組件 import Home from './components/Home.vue'; import New from './components/New.vue'; import User from './components/User.vue';import UserAdd from './components/User/UserAdd.vue';import UserList from './components/User/UserList.vue';//2.配置路由 const routes=[{path:'/home',component:Home},{path:'/news',component:New},{path:'/user',component:User,children:[{path:'useradd',component:UserAdd},{path:'userlist',component:UserList}]},{path:'*',redirect:'/home'} ]//3.實(shí)例化VueRouter const router=new VueRouter({// mode:'history', routes })//4.掛載路由 new Vue({el: '#app',router,render: h => h(App) })//5.在根組件App.vue的模板中,放入<router-view></router-view>

4.路由模塊化

1.在src目錄下新建router目錄,router目錄下新建router.js

import Vue from 'vue'import VueRouter from 'vue-router'; Vue.use(VueRouter);//1.創(chuàng)建組件 import Home from '../components/Home.vue'; import New from '../components/New.vue'; import User from '../components/User.vue';import UserAdd from '../components/User/UserAdd.vue';import UserList from '../components/User/UserList.vue';//2.配置路由 const routes=[{path:'/home',component:Home},{path:'/news',component:New},{path:'/user',component:User,children:[{path:'useradd',component:UserAdd},{path:'userlist',component:UserList}]},{path:'*',redirect:'/home'} ]//3.實(shí)例化VueRouter const router=new VueRouter({// mode:'history', routes })export default router;//5.在根組件App.vue的模板中,放入<router-view></router-view>

2.在src/main.js中

import Vue from 'vue' import App from './App.vue' import router from './router/router.js';//4.掛載路由 new Vue({el: '#app',router,render: h => h(App) })

?

3.element UI的使用

官網(wǎng)

http://element-cn.eleme.io/#/zh-CN/component/installation

?

1.安裝

cnpm i element-ui -S //-S表示 --save

2.將配置代碼引入main.js中

配置代碼:

import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css';Vue.use(ElementUI);

main.js

import Vue from 'vue' import App from './App.vue'//elementsUI 的使用 import ElementUI from 'element-ui'; import 'element-ui/lib/theme-chalk/index.css';Vue.use(ElementUI);import VueRouter from 'vue-router'; Vue.use(VueRouter);//1.創(chuàng)建組件 import Home from './components/Home.vue'; import New from './components/New.vue'; import User from './components/User.vue';import UserAdd from './components/User/UserAdd.vue';import UserList from './components/User/UserList.vue';//2.配置路由 const routes=[{path:'/home',component:Home},{path:'/news',component:New},{path:'/user',component:User,children:[{path:'useradd',component:UserAdd},{path:'userlist',component:UserList}]},{path:'*',redirect:'/home'} ]//3.實(shí)例化VueRouter const router=new VueRouter({// mode:'history', routes })//4.掛載路由 new Vue({el: '#app',router,render: h => h(App) })//5.在根組件App.vue的模板中,放入<router-view></router-view> View Code

?

3.配置webpack.config.js,加入字體配置代碼

配置代碼

{test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,loader: 'file-loader'},

webpack.config.js

var path = require('path') var webpack = require('webpack')module.exports = {entry: './src/main.js',output: {path: path.resolve(__dirname, './dist'),publicPath: '/dist/',filename: 'build.js'},module: {rules: [{test: /\.css$/,use: ['vue-style-loader','css-loader'],}, {test: /\.vue$/,loader: 'vue-loader',options: {loaders: {}// other vue-loader options go here }},{test: /\.js$/,loader: 'babel-loader',exclude: /node_modules/},{test: /\.(png|jpg|gif|svg)$/,loader: 'file-loader',options: {name: '[name].[ext]?[hash]'}},{test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,loader: 'file-loader'}]},resolve: {alias: {'vue$': 'vue/dist/vue.esm.js'},extensions: ['*', '.js', '.vue', '.json']},devServer: {historyApiFallback: true,noInfo: true,overlay: true},performance: {hints: false},devtool: '#eval-source-map' }if (process.env.NODE_ENV === 'production') {module.exports.devtool = '#source-map'// http://vue-loader.vuejs.org/en/workflow/production.htmlmodule.exports.plugins = (module.exports.plugins || []).concat([new webpack.DefinePlugin({'process.env': {NODE_ENV: '"production"'}}),new webpack.optimize.UglifyJsPlugin({sourceMap: true,compress: {warnings: false}}),new webpack.LoaderOptionsPlugin({minimize: true})]) } View Code

然后重啟項(xiàng)目,發(fā)現(xiàn)不報(bào)錯(cuò)了。

?

?4.vuex

vuex是一個(gè)專門為vue.js應(yīng)用程序開(kāi)發(fā)的狀態(tài)管理模式,解決不同組件之間的同一狀態(tài)共享問(wèn)題,數(shù)據(jù)共享問(wèn)題,數(shù)據(jù)持久化

1.安裝

cnpm install vuex --save

2.在src目錄下新建目錄vuex,在vuex目錄下新建store.js文件

import Vue from 'vue' import Vuex from 'vuex'Vue.use(Vuex);// 1.state在vuex中用于儲(chǔ)存數(shù)據(jù) var state={count:1 }// 2.mutations里面放的是方法,方法主要內(nèi)容用于改變state里面的數(shù)據(jù) var mutations={incCount(){++state.count} }// 實(shí)例化Vuex.store const store=new Vuex.Store({state,mutations:mutations })export default store;

3.在src/components/Home.vue中使用

<template><div><h2>這是一個(gè)首頁(yè)組件</h2><button @click="goNews()">通過(guò)js跳轉(zhuǎn)到新聞頁(yè)面</button><!-- 3.使用 --><h2>全局變量--{{this.$store.state.count}}</h2><h2>{{this.i}}</h2><button @click="addcount()">增加數(shù)量+</button></div> </template> <script> // 1.引入store import store from '../vuex/store.js'; // 2.注冊(cè) export default {store,methods:{goNews(){this.$router.push({path:'/news'})},addcount(){// 改變vuex.store里面的數(shù)據(jù)this.$store.commit('incCount');}},data(){return{i:0}},mounted(){this.i=this.$store.state.count} } </script> <style></style>

?

?5.使用iview

官網(wǎng)

https://www.iviewui.com/docs/guide/install

1.安裝

cnpm install iview --save

2.在src/main.js加入

import iView from 'iview' import 'iview/dist/styles/iview.css' // 使用 CSS Vue.use(iView)

3.配置webpack.config.js,加入字體配置代碼

配置代碼

{test: /\.(eot|svg|ttf|woff|woff2)(\?\S*)?$/,loader: 'file-loader'},

webpack.config.js

View Code

然后重啟項(xiàng)目,發(fā)現(xiàn)不報(bào)錯(cuò)了。

?

?

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?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? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

轉(zhuǎn)載于:https://www.cnblogs.com/xuepangzi/p/10091136.html

總結(jié)

以上是生活随笔為你收集整理的vue常用手册的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。