Vue入门一:自动生成的Vue项目展示逻辑分析
我们首先来看一下自动生成的Vue项目
1、main.js
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
指明了根试图是App
2、App.vue
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
指明了这里是两个链接,一个是Home,一个是About
3、About.vue
<template>
<div class="about">
<h1>This is an about page</h1>
</div>
</template>
这里东西很少,就是一个标题而已
4、Home.vue
<script>
// @ is an alias to /src
import HelloWorld from '@/components/HelloWorld.vue'
export default {
name: 'Home',
components: {
HelloWorld
}
}
</script>
在这里引入了HelloWorld.vue
5、HelloWorld.vue
就是我们进来之后展示的很多内容了
<template>
<div class="hello">
<h1>{{ msg }}</h1>
<p>
For a guide and recipes on how to configure / customize this project,<br>
check out the
<a href="https://cli.vuejs.org" target="_blank" rel="noopener">vue-cli documentation</a>.
</p>
<h3>Installed CLI Plugins</h3>
<ul>
<li><a href="https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-babel" target="_blank" rel="noopener">babel</a></li>
<el-button type="primary">主要按钮</el-button>
</ul>
</div>
</template>
<script>
export default {
name: 'HelloWorld',
props: {
msg: String
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
margin: 40px 0 0;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #42b983;
}
</style>
Vue文件的基础格式
<template>
html模板区
</template>
<script>
数据逻辑区
</script>
<style>
样式区
</style>