Vite + Vue3 + TS 第四章 模板语法和指令

本文展示了在Vue组件中如何解析变量,如`msgs`中存储的'guardian2022',以及使用三元运算符根据变量`msg`的值决定显示'INo1'或'INo2'。此外,还演示了如何处理字符串数组,将逗号分隔的数值转换为带人民币符号的数组。这些例子深入浅出地解释了前端开发中的基本操作。
摘要由CSDN通过智能技术生成

​​​​​​ No.1 解析变量名msgs里面的内容:guardian2022

<script setup lang="ts">
const msgs:string='guaridna2022'
</script>

<template>
  <div>
    {{msgs}}
  </div>
  <HelloWorld msg="Vite + Vue" />
</template>

<style scoped>
</style>

打印: guardian2022

 No.2  三元运算表达式:

<script setup lang="ts">
  const msg:number = 1 
</script>

<template>
  {{msg ? 'I No1' : 'I No2'}}
</template>

<style scoped>
</style>

 打印:I No1    

<script setup lang="ts">
  const msg:number = 0 
</script>

<template>
  {{msg ? 'I No1' : 'I No2'}}
</template>

<style scoped>
</style>

  打印:I No2

No3.调用API的json类型 

<script setup lang="ts">
const message:string = "100,200,300,400,500,600"
</script>

<template>
  {{ message.split(',').map(v=> `¥${v}`)  }}
</template>

<style scoped>
</style>

 打印:[ "¥100", "¥200", "¥300", "¥400", "¥500", "¥600" ]

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值