search

Home  >  Q&A  >  body text

javascript - How vue.js file app.vue is called

I am new to vue.js. I only know that main.js is the entry file and app.vue is the total component. Why do I remove the export default code in app.vue and import app from '.app' in main.js? Page But it can display the content in app.vue

App.vue configuration

<template>
  <p id="app">
    <p class='header'>
      I am header!
    </p>
    <p class='tab'>
      I am tab
    </p>
    <p class='content'>
      I am content
    </p>
  </p>
</template>

<script> 
</script>

<style>
</style>

main.js file

import Vue from 'vue';
import App from './App';

Vue.config.productionTip = false;

/* eslint-disable no-new */
new Vue({
  el: '#app',
  template: '<App/>',
  components: { App }
});

Can the app.vue file be received without exportmain.js?

过去多啦不再A梦过去多啦不再A梦2841 days ago794

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-06-12 09:30:39

    Is there no error reported in the terminal?

    reply
    0
  • 世界只因有你

    世界只因有你2017-06-12 09:30:39

    There is nothing wrong with this. Vue does not stipulate that you must use export default. If you want to know the reason, build the example you wrote and look at the code in the generated app.js to know what is going on

    reply
    0
  • 習慣沉默

    習慣沉默2017-06-12 09:30:39

    The role of vue-loader

    https://vue-loader.vuejs.org/...

    <template>
    Default language: html.
    Each .vue file can contain at most one <template> block
    The content will be extracted as a string, which will be compiled and used as the template option for the Vue component.

    Without export, it is equivalent to a component with only template option

    Vue.component('my-component', {
      template: '<span>only template</span>'
    })

    reply
    0
  • Cancelreply