Webstom自定义模板以及模板变量

自定义模板

应用场景:webstorm在新建文件时,往往需要选择文件类型,如:js,vue等。自定义模板的好处在于不用每次新建一个文件都重写相同代码。

  • 以下以新建一个react模板为例
    1. Ctrl+alt+s打开设置
    2. 搜索或找到File and Code Templates
    3. +号新建模板
    4. name:模板名称react, extension文件后缀名:js【在新建file时,即会出现react可供选择】
    5. 编写模板
import React from 'react';
class ${NAME} extends React.Component{
    render() {
        return()
    }
}
export default ${NAME};
  • 如上就是一个react组件模板,其中${NAME}是webstorm的模板变量(对应文件名),在每次新建文件时,${NAME}会被替换成文件名

Webstorm模板变量

${PROJECT_NAME} - the name of the current project(当前项目名).

${NAME} - the name of the new file which you specify in the New File dialog box during the file creation.(文件名)

${USER} - the login name of the current user.(webstorm用户名)

${DATE} - the current system date.(当前日期)

${TIME} - the current system time.(当前时间)

${YEAR} - the current year.(当前年份)

${MONTH} - the current month.(当前月份)

${DAY} - the current day of the month.(当前日期)

${HOUR} - the current hour.(当前小时)

${MINUTE} - the current minute.(当前分)

${PRODUCT_NAME} - the name of the IDE in which the file will be created.

${MONTH_NAME_SHORT} - the first 3 letters of the month name. Example: Jan, Feb, etc.

${MONTH_NAME_FULL} - full name of a month. Example: January, February, etc.
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
回答: 在WebStorm中,你可以通过自定义注释模板来快速生成注释。有几种方法可以实现这个目标。一种方法是在设置中使用活动模板,具体步骤如下:首先,点击设置,然后选择活动模板,再点击右侧的加号,选择Live Template。在缩写处输入你想要的快捷键,比如"///",在描述处输入描述信息,在模板文本处输入注释模板,比如:"/** *@desc *@author sky *@date $date$ */"。\[1\] 另一种方法是点击右上角的"+",然后选择Live Template,填写相关的信息。参考如下:<!-- @name: @description: @author: byx @time: $date$ -->。\[2\] 通过使用这些自定义注释模板,你可以快速生成注释,并且可以根据需要进行修改。这样可以提高你的开发效率。\[3\] #### 引用[.reference_title] - *1* [WebStorm自定义注释模板](https://blog.csdn.net/a15122282003/article/details/79123390)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [WebStorm自定义文档注释模板(也叫设置文档头部注释)](https://blog.csdn.net/sd19871122/article/details/109382098)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Sophie_U

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值