Componentes de archivo único de Vue Technology 19

inserte la descripción de la imagen aquí
Vista.de.la.escuela

<template>
  <!-- 组件的结构 -->
    <div class="demo">
        <h2>学校名称:{
   
   {name}}</h2>
        <h2>学校地址:{
   
   {address}}</h2>
        <button @click="showName">点我提示学校名</button>
    </div>
</template>

<script>
    // 组件交互相关的代码(数据、方法等等)
    export default {
      
      
        name:'School',
        data(){
      
      
            return {
      
      
                name:'尚硅谷',
                address:'北京'
            }
        },
        methods: {
      
      
            showName(){
      
      
                alert(this.name)
            }
        }
    }
</script>

<style>
    /* 组件的样式 */
    .demo{
      
      
        background-color:orange;
    }
</style>

Student.view

<template>
  <!-- 组件的结构 -->
    <div>
        <h2>学生姓名:{
   
   {name}}</h2>
        <h2>学生年龄:{
   
   {age}}</h2>
        <button @click="showName">点我提示学生名字</button>
    </div>
</template>

<script>
    // 组件交互相关的代码(数据、方法等等)
    export default {
      
      
        name:'Student',
        data(){
      
      
            return {
      
      
                name:'张三',
                age:18
            }
        },
        methods: {
      
      
            showName(){
      
      
                alert(this.name)
            }
        }
    }
</script>


aplicación.vue

<template>
    <div>
        <School></School>
        <Student></Student>
    </div>
</template>

<script>
    //引入组件
    import School from './School.vue'
    import Student from './Student.vue'
import Student from './Student.vue';
    export default {
      
      
        name:'App',
        components:{
      
      
    School,
    Student,
    Student
}

    }
</script>


principal.js

import App from './App.vue'

new Vue({
    el:'#root',
    template:`<App></App>`,
    components:{App}
})

índice.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>练习一下单文件组件的语法</title>
</head>
<body>
    <!--准备一个容器-->
    <div id="root"></div>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="./main.js"></script>
</body>
</html>

Supongo que te gusta

Origin blog.csdn.net/qq_40713201/article/details/126396963
Recomendado
Clasificación