vue字符串常用方法、字符串模板
2022/1/15 23:10:02
本文主要是介绍vue字符串常用方法、字符串模板,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script> let str = 'hello world' // 字符串常用方法 console.log(str.startsWith('e')) // false console.log(str.endsWith('d')) // true console.log(str.includes('e')) // true console.log(str.includes("lo")) // true // 字符串模板 使用反引号 let ss = `<div><span>hello world<span> </div> ` console.log(ss) // 2、字符串插入变量和表达式。变量名写在 ${} 中,${} 中可以放 入 JavaScript 表达式。 // 类似于shell传参数 let name = "张三"; let age = 18; let info = `我是${name},今年${age}了`; console.log(info) function fun() { return "这是一个函数" } // 调用函数 let s1 = `字符串模板 调用函数 ${fun()}` console.log(s1) </script> </body> </html>
这篇关于vue字符串常用方法、字符串模板的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-19React Hooks开发入门指南:从零开始学习React Hooks
- 2024-10-19React+TS入门教程:轻松搭建你的第一个React项目
- 2024-10-19React+typescript入门指南:从零开始搭建第一个项目
- 2024-10-19React18进阶:从入门到初级实战教程
- 2024-10-19React进阶:从入门到初级实战指南
- 2024-10-19React进阶:从入门到初级实战指南
- 2024-10-18Hooks进阶:掌握React Hooks的高级技巧
- 2024-10-18Hooks入门:一步步学会React Hooks
- 2024-10-18NextJs入门:简单教程助你轻松上手
- 2024-10-18React18入门:新手必读教程