Vue项目的部分解读

单文件组件与Vue中的路由

根实例 man.js
// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'//表明从当前目录下找App文件App.vue/App.js/App.json依次匹配找到就不在匹配
import router from './router' //当前目录下的router文件夹,自动匹配到index.js

Vue.config.productionTip = false

/* eslint-disable no-new */
new Vue({
  el: '#app',//挂载点指的是index.html中的id为app的元素
  router,//==>router:router
  components: { App },//ES6中键值相同时可省略==>{App:App}
  template: '<App/>'//表明将APP的局部组件显示在页面之上
})
当一个文件以.vue为结尾的时候我们把这个文件叫着单文件组件 ,组件的模版被放在template标签内
<template>
  <div id="app">
    <img src="./assets/logo.png">
    <!-- 显示的是当前路由地址所对应的内容router-view -->
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App'
}
</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>

路由

路由就是根据网址的不同,返回不同的内容给用户

index.js解读

import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    }
  ]
})

当用户访问根目录的时候,我给用户访问的是HelloWorld这个组件

==================================================================

分割线

==================================================================

博主为咯学编程:父母不同意学编程,现已断绝关系;恋人不同意学编程,现已分手;亲戚不同意学编程,现已断绝来往;老板不同意学编程,现已失业三十年。。。。。。如果此博文有帮到你欢迎打赏,金额不限。。。

发布了72 篇原创文章 · 获赞 2 · 访问量 8956

猜你喜欢

转载自blog.csdn.net/qq_36079972/article/details/100541597