mahyuan / Front_end_basics

Anything I can note here about studying
MIT License
1 stars 0 forks source link

vscode snippet user config #8

Open mahyuan opened 6 years ago

mahyuan commented 6 years ago
{
    // Place your snippets for javascript here. Each snippet is defined under a snippet name and has a prefix, body and 
    // description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
    // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the 
    // same ids are connected.
    // Example:
    "Print to console": {
        "prefix": "log",
        "body": [
            "console.log('$1');",
            "$2"
        ],
        "description": "Log output to console"
    },
        "Vue.extent({})": {
        "scope": "javascript,typescript",
        "prefix": "vueextend",
        "body": [
            "import Vue from 'vue'",
            "import jump from 'h5/lib/jump'",
            "import template from './tmpl.html'\n",
            "import optimize from 'filters/imgOptimize'\n",
            "let style = require('./style.css')",
            "if(style.locals) style = style.locals\n",
            "export default Vue.extend({",
                "\ttemplate,",
                "\tdata() {",
                    "\t\treturn {",
                        "\t\t\tstyle,",
                        "\t\t\tsquares: require('icons/squares.png'),",
                    "\t\t}",
                "\t},",
                "\tprops: ['${1:pro}'], ",
                "\tfilters: {",
                    "\t\toptimize,",
                "\t},",
                "\tmethods: {",
                    "\t\tsetClass() {",
                        "\t\t\tlet clazz= {}",
                        "\t\t\tif(this.isOver) clazz[style.over] = true;\n",

                        "\t\t\tif(this.type === 'repo') clazz[style.buy] = true;",
                        "\t\t\telse clazz[style.buy2] = true;",
                        "\t\t\treturn clazz",
                    "\t\t},",
                    "\t\tdetail(g) {",
                        "\t\t\tjump.goods(g.id)",
                    "\t\t},",
                    "\t\tgname(str){",
                        "\t\t\treturn (str || toString(str)).replace('&','&')",
                    "\t\t},",
                "\t},",
                "\tmounted() {",
                    "\t\tconst LazyLoad = require('lib/lazyload')",
                    "\t\tthis.lazyload = new LazyLoad({selector: 'div[data-src], img[data-src]'})",
                "\t},\n",
            "});\n",
        ],
        "description": "createApp for vue template"
    },
    "createApp index.js for vue template js": {
        "scope": "javascript,typescript",
        "prefix": "createApp",
        "body": [
            "import Vue from 'vue';",
            "import axios from 'axios';",
            "import template from './components/${2:valentine/prebuy}/tmpl.html';",
            "import { serverData } from 'lib/init';",
            "import optimize from 'filters/imgOptimize';",
            "import actfooter from './components/activity_footer';",
            "let jump = require('./lib/jump');",
            "let style = require('./components/${2:valentine/prebuy}/style.css');",
            "if (style.locals) style = style.locals;\n",

            "module.exports.createApp = function (${1:imglist}) {",
                "\treturn new Vue({",
                    "\t\ttemplate,",
                    "\t\tdata: {",
                        "\t\t\tmsg: 'hhhh',",
                        "\t\t\tstyle,",
                        "\t\t\t${1:timglist},",
                    "\t\t},",
                    "\t\tfilters: {",
                        "\t\t\toptimize",
                    "\t\t},",
                    "\t\tcomponents: {",
                        "\t\t\tactfooter",
                    "\t\t},",
                    "\t\tmethods: {\n",
                    "\t\t},",
                    "\t\tmounted() {",
                        "\t\t\tlet lazyLoad = require('lib/lazyload');",
                        "\t\t\tnew lazyLoad({",
                            "\t\t\t\tselector: 'div[data-src], img[data-src]'",
                        "\t\t\t});",
                        "\t\t\n",
                        "\t\t\tthis.$nextTick(() => {",
                        "\t\t\n",
                        "\t\t\t})",
                    "\t\t},",
                "\t})",
            "};\n",
            "if (typeof window !== 'undefined') {",
                "\tconst sd = serverData();",
                "\twindow.app = exports.createApp(sd.${1:imglist});",
                "\tapp.$mount('#app');",
            "};\n",
        ],
        "description": "createApp for vue template"
    },
    "create router for koa router file": {
        "scope": "javascript,typescript",
        "prefix": "router",
        "body": [
            "// ",
            "router.get('${1:/activity/valentine/prebuy}', function* (next) {",
                "\tconst share = {",
                    "\t\ttitle: '${2:this is share title}',",
                    "\t\tcontent: '${3:this is share content}',",
                    "\t\ticon_url: '${4:this is share icon url}',",
                    "\t\ttarget_url: `${5:https://h5.xiaohongchun.com${this.originalUrl}}`",
                "\t};\n",
                "\tlet ${6:imglist} = require(${7:'../../views/h5/activity/valentine/prebuy_data.json'});\n",

                "\tlet app = require('../../../../ssr/${8:h5/valentine_prebuy}').createApp(${6:imglist});",
                "\tlet __html = yield render(app);\r",

                "\tyield this.render(${9:'h5/activity/valentine/prebuy'}, {",
                    "\t\t__title: share.title,",
                    "\t\t__html,",
                    "\t\t${6:imglist},",
                    "\t\t__name: ${8:'h5/valentine_prebuy'},",
                    "\t\t__shareinfo: {",
                        "\t\t\tpengyouquan: share,",
                        "\t\t\tweixin: share,",
                        "\t\t\tqqzone: share,",
                        "\t\t\tweibo: share,",
                        "\t\t\tqq: share",
                    "\t\t}",
                "\t})",
            "});\n",
        ],
        "description": "create router for koa router file"
    },
    "views  file *.ejs": {
        "prefix": "views",
        "scope": "ejs",
        "body": [
            "<%- include(${1:'../../../common/h5-header'}) %>",
            "<%- include(${2:'../../../common/h5-common'}) %>\n",
                "\t<div id='${3:app}'><%- ${4:__html} %></div>",
                "\t<pre vue-data='${5:imglist}'><%-  escape(JSON.stringify(${5:imglist}) %></pre>\n",
            "<%- include(${6:'../../../common/h5-footer'}) %>"
        ],
        "description": " views file ejs template "
    }
}