project.code-snippets 2.23 KB
{
	"小程序页面模板": {
		"prefix": "page",
		"scope": "javascript",
		"body": [
			"Page({",
			"\tdata: {",
			"\t\tnavBarHeight: 0,",
			"\t},",
			"",
			"\tnavbarReady(e) {",
			"\t\tlet navBarHeight = e?.detail?.height;",
			"\t\tthis.setData({",
			"\t\t\tnavBarHeight,",
			"\t\t});",
			"\t},",
			"",
			"\tback() {",
			"\t\twx.\\$router.back();",
			"\t},",
			"",
			"\tonLoad(options) {",
			"\t\t$1",
			"\t},",
			"",
			"\tonRoute(options) {",
			"\t\tconsole.log(options);",
			"\t},",
			"",
			"\t/**",
			"\t * 生命周期函数--监听页面隐藏",
			"\t */",
			"\tonHide() {},",
			"",
			"\t/**",
			"\t * 生命周期函数--监听页面卸载",
			"\t */",
			"\tonUnload() {},",
			"",
			"\t/**",
			"\t * 页面相关事件处理函数--监听用户下拉动作",
			"\t */",
			"\tonPullDownRefresh() {},",
			"",
			"\t/**",
			"\t * 页面上拉触底事件的处理函数",
			"\t */",
			"\tonReachBottom() {}",
			"});",
		],
		"description": "微信小程序 Page 页面模板(含 navbarReady / back)",
	},
	"小程序组件模板": {
		"prefix": "component",
		"scope": "javascript",
		"body": [
			"Component({",
			"  /**",
			"   * 组件的属性列表",
			"   */",
			"  properties: {",
			"    ${1:exampleProp}: {",
			"      type: ${2:String},",
			"      value: ${3:''},",
			"      observer: function(newVal, oldVal) {",
			"        $4",
			"      }",
			"    }",
			"  },",
			"",
			"  /**",
			"   * 组件的初始数据",
			"   */",
			"  data: {",
			"    ${5:exampleData}: ${6:null}",
			"  },",
			"",
			"  /**",
			"   * 组件的方法列表",
			"   */",
			"  methods: {",
			"    ${7:exampleMethod}() {",
			"      $0",
			"    }",
			"  },",
			"",
			"  /**",
			"   * 组件生命周期函数",
			"   */",
			"  lifetimes: {",
			"    created() {",
			"      ",
			"    },",
			"    attached() {",
			"      ",
			"    },",
			"    ready() {",
			"      ",
			"    },",
			"    moved() {",
			"      ",
			"    },",
			"    detached() {",
			"      ",
			"    }",
			"  },",
			"",
			"  /**",
			"   * 组件数据监听器",
			"   */",
			"  observers: {",
			"  }",
			"})",
		],
		"description": "微信小程序 Component 完整模板(含 properties, data, methods, lifetimes, observers)",
	},
}