当前位置: 首页 > news >正文

Vue3【四】使用Vue2的写法写一个新的组件子组件和根组件

Vue3【四】使用Vue2的写法写一个新的组件

Vue3【四】使用Vue2的写法写一个新的组件
Vue3是向下兼容的,所有可以使用Vue的选项式写法

运行截图

在这里插入图片描述

目录结构

目录结构

文件源码

App.vue

<template><div class="app"><h1>你好世界! 我是App根组件</h1><Person /></div>
</template><script lang="ts">
import Person from './components/Person.vue'
export default {name: 'App', //组件名字// 注册组件components: {Person}
}</script><style>
.app {background-color: #4fffbb;box-shadow: 0 0 10px;border-radius: 10px;padding: 20px;
}
</style>

Persion.vue

<template><div class="person"><h1>我是Person组件</h1><h2>姓名:{{ name }}</h2><h2>年龄:{{ age }} </h2><button @click="changeName">修改名字</button><button @click="changeAge">修改年龄</button><button @click="showAdd">查看信息</button></div>
</template><script lang="ts">
export default {name: 'Person', //组件名字// Vue2 方式写的数据data() {return {name: "太上老君",age: 18000,add: '太上老君是公认的道教始祖,即道教中具有开天创世与救赎教化的太上道祖。'}},methods: {showAdd() {alert(this.add)},changeName(){this.name = this.name == "太白金星"?'太上老君':'太白金星'},changeAge(){this.age += 1}}
}</script><style>
.person {background-color: #ff9e4f;box-shadow: 0 0 10px;border-radius: 30px;padding: 30px;
}
button{margin:0 10px;padding: 0 5px;box-shadow: 0 0 5px;;
}
</style>
http://www.lryc.cn/news/365872.html

相关文章:

  • 指标体系建设10大坑
  • ubuntu 20.04上docker 使用gpu
  • 短剧系统投流版开发,为运营公司投流业务赋能
  • 入坑必看的几个嵌入式方向热点问题
  • 电能表如何与智能家居进行有效的融合
  • jmeter多用户登录并退出教程
  • 阿里云ECS实例镜像本地取证
  • 不要硬来!班组管理有“巧思”
  • [原创][Delphi多线程]使用TMonitor和TQueue配合实现TThreadedQueue的经典使用案例.
  • vue3 基于el-tree增加、删除节点(非TypeScript 写法)
  • 小抄 20240607
  • 【GIS教程】土地利用转移矩阵
  • API接口测试工具:jmeter的安装、汉化、Jmeter桌面快捷图标和基本使用
  • 电动汽车使用时,这10个方面需要引起重视。
  • SD-WAN加速跨国服务器访问
  • Vue2指令
  • kafka-集群搭建(在docker中搭建)
  • 特征交叉系列:DCN-Mix 混合低秩交叉网络理论和实践
  • python项目(豆瓣电影)
  • 精选网络安全书单:打造数字世界的钢铁长城!
  • Ubuntu由于没有公钥,无法验证下列签名。
  • 水库安全监测系统:智慧水文动态监测系统
  • 下载centos7镜像及在VMware上安装Linux (Centos7)操作系统详细教程
  • 【全开源】考试答题系统源码(FastAdmin+ThinkPHP+Uniapp)
  • toB市场 | 我们喜欢赞助这样的展会活动
  • 【学习笔记】Git常用命令
  • 【C/C++】IO流
  • Vite5+Vue3整合Tailwindcss详细教程
  • 小程序 UI 风格魅力非凡
  • 【常用工具系列】Git 教程——从入门到大师