vue 引用其他组件
2024-08-30 12:06:07
1、在components 目录下新建Test.vue 文件
<template>
<div class="test">
<h1>{{ msg }}</h1>
<router-link to="/login">跳转到详情页</router-link>
</div>
</template> <script>
export default {
name: 'test',
data () {
return {
msg: 'this.test uve'
}
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
} ul {
list-style-type: none;
padding: 0;
} li {
display: inline-block;
margin: 0 10px;
} a {
color: #42b983;
}
</style>
2、在Hell.vue里添加代码引用Test.vue
<template>
<div class="hello"> <h1>{{ msg }}</h1>
<!-- 引用的组件标签 和下边 import 的名称保持一致 -->
<test></test>
</div> </template> <script>
// 引用Test.vue 命名为test
import test from './Test'
export default {
name: 'hello',
// 引用组件
components:{
test
},
data () {
return {
msg: 'Welcome to Your Vue.js App'
}
}
}
</script> <!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
font-weight: normal;
} ul {
list-style-type: none;
padding: 0;
} li {
display: inline-block;
margin: 0 10px;
} a {
color: #42b983;
}
</style>
运行结果:
最新文章
- SignalR快速入门 ~ 仿QQ即时聊天,消息推送,单聊,群聊,多群公聊(基础=》提升)
- java良好的编码习惯
- Hibernate的关联映射关系
- vim 分屏显示
- URL编码知识摘抄备忘
- 借助 SublimeLinter 编写高质量的 JavaScript &; CSS 代码
- [stm32] GPIO及最小框架
- P142-1
- Using FastCGI to Host PHP Applications on IIS 7 -IIS7 怎么配置 PHP5
- 用apache的httpclient发请求和接受数据
- FatMouse&;#39; Trade(杭电1009)
- hdu 1150 Machine Schedule(最小顶点覆盖)
- application19事件 20多少步骤 具体20多少只有微软知道!!!
- TemplateMethod-模板模式
- zTree基础
- python 容器类型数据 (str list tuple set dict)
- 指向函数的指针 ------ 函数指针(function pointer)
- Python3入门(十)——调试与测试
- [CF1062F]Upgrading Cities[拓扑排序]
- UI---------EventSystem