Vue项目代码结构介绍
原创约 501 字大约 2 分钟...
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这个组件
分割线
相关信息
以上就是我关于 Vue项目代码结构介绍 知识点的整理与总结的全部内容,希望对你有帮助。。。。。。。
Powered by Waline v2.15.4