vue+tsx

本文详细介绍了如何在Vue项目中使用tsx语法。通过Vue-cli创建项目后,删除默认内容,修改router的index.ts,新建App.tsx,并在src目录下创建pages文件夹,包含index.tsx和login子文件夹。最后,展示了tsx代码示例,完成Vue项目的基本结构搭建。
摘要由CSDN通过智能技术生成

在Vue中使用tsx语法进行项目构建

首先进行Vue项目的搭建,想必大家都会使用Vue-cli进行项目的搭建,这里我给大家说一下步骤:

  • 使用 vue create vue-tsx进行项目创建,我选择自定义进行创建
    在这里插入图片描述
  • 接着选择自己在项目中需要用到的一些插件和预处理器,这个我就不说明了,不明白的可以去查一查如何使用vue-cli进行创建vue项目。
  • 删除views文件夹,删空components文件夹中的内容保留文件夹,删除App.vue文件。
    在这里插入图片描述
  • 接着修改router下的index.ts文件:
import Vue from "vue";
import VueRouter, {
    RouteConfig } from "vue-router";
import Index from "../pages/index";

Vue.use(VueRouter);

const routes: Array<RouteConfig> = [
  {
   
    path: "/",
    name: "index",
    component: Index,
  },
  {
   
    path
时钟秒数 dig_out : out std_logic_vector(23 downto 0) -- 数码管输出 ); end clock; architecture Behavioral of clock is signal cnt_24h : integer range 0 to 86399 := 0;是的,你可以使用 Vue + TSX 来实现这样的目录展开和折叠功能的组件。 下 -- 当前时间(秒) signal cnt_sec : integer range 0 to 59 := 0; -- 秒面是一个简单的示例代码,展示了如何使用 Vue + TSX 来实现一个基本的目录计数器 signal cnt_min : integer range 0 to 59 := 0; -- 分钟计数器树组件: ```tsx import { defineComponent } from 'vue' interface TreeNode { name: string; children?: TreeNode[]; signal cnt_hour : integer range 0 to 23 := 0; -- 小时计数器 signal} export default defineComponent({ name: 'Tree', props: { treeData: { type: Array as () => TreeNode dig_sel : std_logic_vector(1 downto 0) := "00"; -- 数码管选择信号 signal[], required: true } }, data() { return { expandedNodes: [] as string[] } }, dig_data : std_logic_vector(3 downto 0) := "0000"; -- 数码管数据信号 begin methods: { toggleNode(nodeName: string) { if (this.expandedNodes.includes(nodeName)) { this.expanded -- 时钟计数器 process (clk, reset) begin if reset = '1' then Nodes = this.expandedNodes.filter(n => n !== nodeName) } else { this.expandedNodes.push(nodeName) } cnt_24h <= 0; cnt_sec <= 0; cnt_min <= 0; cnt_hour <= 0 } }, render() { const renderTreeNode = (node: TreeNode) => { const isExpanded = this.expandedNodes.includes; elsif rising_edge(clk) then if enable = '1' then cnt_24h <= cnt_24h(node.name) return ( <div> <div onClick={() => this.toggleNode(node.name)}>{isExpanded ? '-' : '+' + 1; if cnt_24h = 86399 then cnt_24h <= 0; end if; } {node.name}</div> {isExpanded && node.children?.map(child => renderTreeNode(child))} </div> ) cnt_sec <= cnt_sec + 1; if cnt_sec = 60 then cnt_sec <= 0; cnt_min <= cnt_min + 1; if cnt_min = 60 then cnt_min <= 0; cnt_hour <= } return ( <div> {this.treeData.map(node => renderTreeNode(node))} </div> ) } }) cnt_hour + 1; if cnt_hour = 24 then cnt_hour <= 0; end if; end``` 在上面的代码中,`Tree` 组件接收一个 `treeData` 属性,该属性是一个树形结 if; end if; end if; end if; end process; -- 数码管控制 process构的数据,每个节点包含一个 `name` 属性和一个可选的 `children` 数组。组件内部 (cnt_sec, cnt_min, cnt_hour) begin case dig_sel is when "00" => dig_data <=使用 `expandedNodes` 数组来跟踪当前展开的节点。当用户点击某个节点时,会触发 `toggle cnt_sec mod 10; when "01" => dig_data <= cnt_sec / 10; when "10" => Node` 方法,该方法会根据节点名来判断该节点是否已展开。最后,在 `render` 方法中使用 dig_data <= cnt_min mod 10; when "11" => dig_data <= cnt_min / 10; end case; 递归来渲染整个树形结构。 注意,在上面的代码中,我们使用了 TypeScriptTSX 语 end process; -- 数码管扫描 process (clk) begin if rising_edge(clk) then 法。如果你不熟悉这些语言特性,建议先学习一下。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值