组件.定义&组件

12003

定义组件

创建/view/component/playground/component-create-example01.html

  1. <template id="component-create-example01">
  2. <div>
  3. <p>这是一个组件案例</p>
  4. <p>{{ exampleTitle }}</p>
  5. </div>
  6. </template>
  7. <script type="module">
  8. Vue.component("component-create-example01", {
  9. template: '#component-create-example01',
  10. props: ['exampleTitle'],
  11. data: () => ({
  12. }),
  13. computed: {},
  14. watch: {},
  15. async created() { },
  16. mounted() { },
  17. methods: {}
  18. })
  19. </script>

使用组件

  1. <v-app>
  2. <component-create-example01 :example-title="title"/>
  3. </v-app>
  4. {% include 'component/playground/component-create-example01.html' %}
  5. <script type="module">
  6. new Vue({
  7. el: '#app',
  8. template: '#app-template',
  9. vuetify: new Vuetify(),
  10. data:{
  11. title: "这是来自父页面的标题!"
  12. },
  13. })
  14. </script>