vue.js 初建项目时的内容
新建好的vue项目,运行时页面时这样的
主要的文件是根目录下的index.html和src目录下的App.vue,main.js文件
其中index.html就是放置了一个层<div id="app"></div>,其余交给了App.vue模板去实现了
在App.vue文件的代码如下:
<template>
<div id="app">
<img src="./assets/logo.png">
<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>
App.vue定义了一个模板组件,一个.vue只能有一个template来使用,并且在<template></template>必须只有一个<div>,上面的代码中,就使用了<div id="app">与index.html对应
<router-view/>又引用了另一个路由组件,在src/router/index.js传进了HelloWorld.vue.
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中写的.
#跟随大神的脚步,自己也记录一下所学的内容,仅此而已#