1、在webstorm中,點擊file菜單欄,進入settings設置選項
2、選中Editor中的live Templates(動態模板)
3、點開javascript,點擊+添加按鈕
4、填寫模板
註釋:
(1)Abbreviation(縮寫):填寫了can,即輸入can按tap鍵,就會自動生成代碼模板
(2)description:模板介紹
(3)Templates text:模板文字內容,如:我的模板是:
(function () {
var canvas = document.querySelector("#canvas");
var context = canvas.getContext("2d");
canvas.height = 500;
canvas.width = 500;
context.beginPath();
context.moveTo(0,0);
context.closePath();
context.stroke();
}());
5、點擊Define,勾選Javascript,完成自定義
6、Apply、OK,應用、確認
7、使用模板
新建一個html,在<script>標籤內,輸入can,按tab鍵,即會生成代碼塊。(其他標籤內只會生成<can></can>。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>蔣士鈞 2018.07.15</title>
</head>
<body>
<script>
(function () {
var canvas = document.querySelector("#canvas");
canvas.height = 500;
canvas.width = 500;
var context = canvas.getContext("2d");
context.beginPath();
context.moveTo(0,0);
context.closePath();
context.stroke();
}());
</script>
</body>
</html>