vue文件流程

vue文件流程

index.html (入口文件) -->main.js (执行main.js) --> App.vue(实例化vue对象)

index.html 入口文件

// index.html 入口文件
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>vue-playlist</title>
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

main.js (执行main.js)

//main.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'

Vue.config.productionTip = false

// 全局注册组件
// Vue.component("users",Users)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App }, // 要想模板能调用组件,必须先注册
  template: '<App/>' // 组件调用的标签或div等
})

// index.html(入口文件) -> main.js ->App.vue(根组件)

App.vue(根组件)

<!--1.模板:html结构-->

<template>
  <div id="app">
    <h1>{{title}}</h1>
    <users></users>
  </div>
</template>

<!--2.行为:处理逻辑-->

<script>

import Users from './components/Users'

export default {
  name: 'app',
  data(){
    return {
      title:" 这是我的第一个vue脚手架项目"
    }
  },
  components: {
   "users":Users
  }
}
</script>

<!--2.样式:解决样式-->
<style>

</style>

两个组件之间产生关联,先在vue实例中import, 再注册,然后调用。

全局组件:在main.js文件中import并注册。


import Users from './components/Users'

// 全局注册组件
Vue.component("users",Users)

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App }, // 要想模板能调用组件,必须先注册
  template: '<App/>' // 组件调用的标签或div等
})

猜你喜欢

转载自blog.csdn.net/Mandyucan/article/details/83785915