Vue入门笔记 day2

2018-03-09  本文已影响0人  12345ss

复习

过滤器

获取DOM元素

mint-ui

wappalyzer

vue-router

vue-router

eg
main.js

//引入Vue
import Vue from 'vue';
import VueRouter from 'vue-router';

//引入app.vue
import App from './components/app.vue';
import Music from './components/music.vue';
import Movie from './components/movie.vue';


//安装插件

Vue.use(VueRouter); //挂载属性

//创建路由对象并配置路由规则
let router = new VueRouter({
    //routers
    routes: [{
        name: 'music',
        path: '/music',
        component: Music
    }, {
        name: 'movie',
        path: '/movie',
        component: Movie
    }]
});

//new Vue
new Vue({
    el: '#app',
    //让Vue知道路由规则
    router: router,
    render: c => c(App)
})

app.vue

<template>
    <div>
        <div class="h">
            头部
            <!-- a标签 -->

            <a href="#/music">音乐</a>
            <a href="#/movie">电影</a>
            
            <!-- to:去哪里 -->
             
            <router-link :to="{name:'music'}">音乐</router-link>
            <router-link :to="{name:'movie'}">电影</router-link> 
            
            <!-- 也可以根路径用 -->
             
            <router-link to="/music">音乐</router-link>
            <router-link to="/movie">电影</router-link> 
            
        </div>
        <router-view class="b"></router-view>
        <div class="f">底部</div>
    </div>
</template>
<script type="text/javascript">
export default {
    data() {
        return {

        }
    }
}
</script>
<style type="text/css" scoped>
.h {
    height: 100px;
    background: yellowgreen;
}

.b {
    height: 100px;
    background: skyblue;
}

.f {
    height: 100px;
    background: hotpink;
}
</style>

参数 router-link

编程导航

复习

重定向和404

多视图

嵌套路由


    //其组件内包含着第一层的router
    {
        name:'music',
        path:'/music',
        component:Music,
        children:[ //子路由的path /就是绝对路径  不/就是相对路径
            {name:'music.oumei',path:'oumei',component:Oumei},
            {name:'music.guochan',path:'guochan',component:Guochan}
            //name:'music_oumei',格式不固定,只是为了表明父子级关系
        ]
    }

vue-resource(了解)

axios

如何练习

上一篇 下一篇

猜你喜欢

热点阅读