Vue.js第二天學(xué)習(xí)筆記(vue-router)
vue中vue-router的使用:
main.js如何配置(es6的寫法):在引用之前記得先 npm 下所需要的vue
import Vue from 'vue' import App from './App.vue' import Router from 'vue-router' import Resource from 'vue-resource' //import VueTouch from 'vue-touch' var VueTouch = require('vue-touch') //引入home頁面 import homepage from './page/home.vue' //引入test頁面 import test from './page/test.vue' Vue.use(Router); Vue.use(Resource); Vue.use(VueTouch); var router = new Router({ abstract: true, hashbang: false }); //實現(xiàn)頁面跳轉(zhuǎn) router.map({ '/home':{ component:homepage }, '/test':{ component:test }, }) router.start(App, '#app') // router.go('test'); 默認直接跳轉(zhuǎn)到 test 頁面
index.html中引入app.vue和build.js
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>vue.js學(xué)習(xí)筆記(2)</title> <link rel="stylesheet" type="text/css" href="style/bootstrap.css"> </head> <body> <!--此處注意加載順序,需要先加載dom在加載js,否則會'Cannot find element: #app'--> <div id='app'></div> <script src="static/build.js"></script> </body> </html> <style> body { } </style>
app.vue引入router
<template> <div class='all-container'> <div class="public-content">我是公共頁面</div> <div class='menu'> <ul class="list"> <li><a v-link='"/home"'>home頁面</a></li> <li><a v-link='"/test"'>test頁面</a></li> </ul> </div> <router-view transition='animation' class='container' keep-alive></router-view> </div> </template>
home.vue
<template> <div class="home"> <div class="htmleaf-content"> 我是home頁面的內(nèi)容 </div> </div> </template>
test.vue
<template> <div class="test"> <div class="test-content"> 我是test頁面的內(nèi)容 </div> </div> </template>
最后用webpack 將程序打包.關(guān)于webpack大家可以看看
本文已被整理到了《Vue.js前端組件學(xué)習(xí)教程》,歡迎大家學(xué)習(xí)閱讀。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue?webpack打包原理解析(全網(wǎng)最新最全)
webpack是讓我們可以進行模塊化開發(fā),并且會幫助我們處理模塊間的依賴關(guān)系,這篇文章主要介紹了vue?webpack打包原理,本篇介紹的有點長,希望大家耐心閱讀2023-02-02vue作用域插槽詳解、slot、v-slot、slot-scope
這篇文章主要介紹了vue作用域插槽詳解、slot、v-slot、slot-scope,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-03-03解決el-upload批量上傳只執(zhí)行一次成功回調(diào)on-success的問題
這篇文章主要介紹了解決el-upload批量上傳只執(zhí)行一次成功回調(diào)on-success的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-03-03在Vue環(huán)境下利用worker運行interval計時器的步驟
這篇文章主要介紹了在Vue環(huán)境下利用worker運行interval計時器的步驟,本文分步驟給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-08-08