<template> <div class="app"> <h1>{{msg}}</h1> <School :getSchoolName="getSchoolName"/> <Student/> </div> </template> <script> import Student from './components/Student.vue' import School from './components/School.vue' export default { name: 'App', components:{School,Student}, data() { return { msg: 'Hello' } }, methdos: { getSchoolName(name){ console.log('App收到了学校名:',name) }, }, } </script> <style scoped> .app { background-color: gray; padding: 5px; } </style>
时间: 2023-08-17 15:26:24 浏览: 153
这段代码中有一个拼写错误。在 `methods` 中,将 `methdos` 改为 `methods` 即可。改正后的代码如下:
```
<template>
<div class="app">
<h1>{{msg}}</h1>
<School :getSchoolName="getSchoolName"/>
<Student/>
</div>
</template>
<script>
import Student from './components/Student.vue'
import School from './components/School.vue'
export default {
name: 'App',
components:{School,Student},
data() {
return {
msg: 'Hello'
}
},
methods: {
getSchoolName(name){
console.log('App收到了学校名:',name)
},
},
}
</script>
<style scoped>
.app {
background-color: gray;
padding: 5px;
}
</style>
```
相关问题
修改改正这段代码: <template> <div id="app"> {{ message }} </div> <div class="hello"> <img src="../assets/logo.png"> <h1>{{ msg }}</h1> </div> </template> <script> var exampleData = { message: "Hello World! " }; var vm=new Vue({ el: '#app', data: exampleData }); </script>
```html
<template>
<div id="app">
<div>{{ message }}</div>
<div class="hello">
<img src="../assets/logo.png">
<h1>{{ msg }}</h1>
</div>
</div>
</template>
<script>
var exampleData = {
message: "Hello World!"
};
var vm = new Vue({
el: '#app',
data: exampleData
});
</script>
```
在修改后的代码中,主要是将`{{ message }}`包裹在一个`<div>`标签中,保持代码的结构清晰。同时,调整了缩进,使代码更易读。
阅读全文