{"id":68358,"date":"2019-08-14T13:55:04","date_gmt":"2019-08-14T05:55:04","guid":{"rendered":"http:\/\/www.xiaoyebailong.com\/?p=68358"},"modified":"2019-08-15T13:56:14","modified_gmt":"2019-08-15T05:56:14","slug":"%e5%b0%8f%e7%a8%8b%e5%ba%8f%e8%bd%acvue%e9%9d%99%e6%80%81","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2019\/08\/14\/68358.htm","title":{"rendered":"\u5c0f\u7a0b\u5e8f\u8f6cvue\u9759\u6001"},"content":{"rendered":"\n<p>\u524d\u8a00\uff0c\u8fd9\u4e2a\u5c0f\u63d2\u4ef6\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u628a\u539f\u6709\u7684\u5c0f\u7a0b\u5e8f\u754c\u9762\u5feb\u901f\u8f6c\u6210vue\u6846\u67b6\u80fd\u7528\u7684\u754c\u9762\u8282\u7701\u65f6\u95f4\uff0c\u4e0d\u5305\u542bjs \u90e8\u5206<br>\n\u4f7f\u7528\u6dd8\u5b9d\u7684 flexible.js \u65b9\u6848 \u6240\u4ee5 1rem = 75px \uff0c\u4f7f\u7528\u5176\u4ed6\u65b9\u6848\u7684rem \u53ef\u4ee5\u81ea\u884c\u66ff\u6362\u76f8\u5173\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\/\/\u4f5c\u8005 \uff1a\u54ab\u5c3a\u5929\u6daf \u8054\u7cfb\u65b9\u5f0f 827324885 \n\/\/1.1.1\u7248\u672c\u66f4\u65b0\u5185\u5bb9\n\/\/\u66f4\u65b0\u90e8\u5206\u6b63\u5219  \u5220\u9664\u90e8\u5206\u5c0f\u7a0b\u5e8f\u72ec\u6709\u4f46vue\u7528\u4e0d\u5230\u800c\u4e14\u53ef\u80fd\u5f15\u8d77\u62a5\u9519\u7684\u90e8\u5206\n\/\/\u4f7f\u7528\u6559\u7a0b \u548cpage\u6587\u4ef6\u540c\u7ea7\u5373\u53ef \n\/\/cmd \u5230\u672c\u6587\u4ef6\u76ee\u5f55\u4e0b \u7136\u540e\u6267\u884c node index.js  \n\/\/\u4f1a\u81ea\u52a8\u751f\u6210 .vue .css\u6587\u4ef6 \u4e0d\u5f71\u54cd\u539f\u5c0f\u7a0b\u5e8f\u8fd0\u884c\nvar fs = require(\"fs\");\nvar path = require('path'); \/\/\u89e3\u6790\u9700\u8981\u904d\u5386\u7684\u6587\u4ef6\u5939\nvar filePath = path.resolve('.\/pages');\nfileDisplay(filePath);\n\nfunction fileDisplay(filePath) {\n   \/\/\u6839\u636e\u6587\u4ef6\u8def\u5f84\u8bfb\u53d6\u6587\u4ef6\uff0c\u8fd4\u56de\u6587\u4ef6\u5217\u8868\n   fs.readdir(filePath, function(err, files) {\n       if(err) {\n           console.warn(err)\n       } else {\n           \/\/\u904d\u5386\u8bfb\u53d6\u5230\u7684\u6587\u4ef6\u5217\u8868\n           files.forEach(function(filename) {\n               \n               var s = '.\/pages\/' + filename;\n               fs.readdir(s, function(err, filesList) {\n                   if(err) {\n                       console.warn(err)\n                   } else {\n                       \/\/\u8bfb\u53d6\u6bcf\u4e2a\u6587\u4ef6\n                       for(var i = 0; i &lt; filesList.length; i++) {\n                           getfileList(s + '\/' + filesList[i], s, filename)\n                       }\n                   }\n               });\n           });\n       }\n   });\n}\n\nfunction getfileList(flieName, ord, filename) {\n   fs.readFile(flieName, 'utf8', function(err, data) {\n       if(err) {\n           console.warn(err)\n       } else {\n           \/\/html\u90e8\u5206\u8f6c\u6362\n           if(flieName.indexOf(\"wxml\") != -1) {\n               var dataName = '&lt;template>&lt;div>' + data;\n               replaceHtml(dataName, ord, flieName, filename)\n           }\n           \/\/css\u90e8\u5206\u6293\u83b7\n           if(flieName.indexOf(\"wxss\") != -1) {\n               replaceCss(data, ord, flieName, filename)\n           }\n       }\n   });\n}\n\nfunction replaceCss(fileContent, fileUrl, s, fileName) {\n   var str = fileContent;\n       str = str.replace(\/image\/g, 'img');\n   str = str.replace(\/navigator\/g, 'a');\n   str = str.replace(\/\\d+rpx\/g, function(a, b, c, d, e, f) {\n       return(parseInt(a) \/ 75).toFixed(2) + 'rem';\n   });\n   var s = '&lt;style scoped>' + str + '&lt;\/style>';\n   fs.writeFileSync(fileUrl + '\/' + fileName + '.css', s);\n}\n\nfunction replaceHtml(fileContent, fileUrl, s, fileName) {\n   var str = fileContent;\n   str = str.replace(\/image\/g, 'img');\n   str = str.replace(\/view\/g, 'div');\n   str = str.replace(\/text\/g, 'span');\n   str = str.replace(\/bindtap\/g, '@onclick');\n   str = str.replace(\/block\/g, 'template');\n   str = str.replace(\/wx:if\/g, 'v-show');\n   str = str.replace(\/src=\\'\\{\\{\/g, \":src='\");\n   str = str.replace(\/wx\\:key=\\\"\\*this\\\"\/g, ' ');\n   str = str.replace(\/wx\\:key\\=\\\"index\\\"\/g, ' ');\n   str = str.replace(\/navigator\/g, 'router-link');\n   str = str.replace(\/wx:for=\"{{\/g, 'v-for= \"(item,index) in ');\n   str = str.replace(\/url\\=\\'..\\\/\/g, \"to='\");\n   str = str.replace(\/bindinput\/g, '@input');\n\n   \/\/\u56fe\u7247\u8def\u5f84\u66ff\u6362\n   str = str.replace(\/..\\\/..\\\/imgs\/g, function(a, b, c, d, e, f) {\n       return '..\/assets';\n   });\n   \/\/rpx\u8f6crem \n   str = str.replace(\/\\d+rpx\/g, function(a, b, c, d, e, f) {\n       return(parseInt(a) \/ 75).toFixed(2) + 'rem';\n   });\n\n   str += '&lt;\/div>'\n   str += '&lt;\/template>';\n   str += '&lt;script>' + 'import vue from \"vue\"' + 'var vm = vue;' + 'export default {' + 'name:\"' + fileName + '\",' + ' data() {return {}}, ' + 'methods: {} ' + '}' + '&lt;\/script>';\n   \/\/\u65b0\u5efa\u6587\u4ef6\n   fs.writeFileSync(fileUrl + '\/' + fileName + '.vue', str);\n}\n<\/pre>\n\n\n\n<p>html\u90e8\u5206\u7f16\u8bd1\u524d<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/\/upload-images.jianshu.io\/upload_images\/5145653-96ff2677ac5b6f4c.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/976\/format\/webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\n\nimage.png\n<br><\/p>\n\n\n\n<p>html\u90e8\u5206\u7f16\u8bd1\u540e<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/\/upload-images.jianshu.io\/upload_images\/5145653-82a51fc904d6f686.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/879\/format\/webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\n\nimage.png\n\n<\/p>\n\n\n\n<p>css\u90e8\u5206\u7f16\u8bd1\u524d<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/\/upload-images.jianshu.io\/upload_images\/5145653-8692789bb2499f06.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/430\/format\/webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\n\nimage.png\n<br><\/p>\n\n\n\n<p>css\u90e8\u5206\u7f16\u8bd1\u540e<br><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/\/upload-images.jianshu.io\/upload_images\/5145653-f0104f3344807586.png?imageMogr2\/auto-orient\/strip%7CimageView2\/2\/w\/494\/format\/webp\" alt=\"\"\/><\/figure>\n\n\n\n<p>\n\nimage.png<\/p>\n\n\n\n<p>\u4f5c\u8005\uff1azcty0701<br>\u94fe\u63a5\uff1ahttps:\/\/www.jianshu.com\/p\/d6e92a3b80f4<br>\u6765\u6e90\uff1a\u7b80\u4e66<br>\u7b80\u4e66\u8457\u4f5c\u6743\u5f52\u4f5c\u8005\u6240\u6709\uff0c\u4efb\u4f55\u5f62\u5f0f\u7684\u8f6c\u8f7d\u90fd\u8bf7\u8054\u7cfb\u4f5c\u8005\u83b7\u5f97\u6388\u6743\u5e76\u6ce8\u660e\u51fa\u5904\u3002\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00\uff0c\u8fd9\u4e2a\u5c0f\u63d2\u4ef6\u53ea\u662f\u4e3a\u4e86\u65b9\u4fbf\u628a\u539f\u6709\u7684\u5c0f\u7a0b\u5e8f\u754c\u9762\u5feb\u901f\u8f6c\u6210vue\u6846\u67b6\u80fd\u7528\u7684\u754c\u9762\u8282\u7701\u65f6\u95f4\uff0c\u4e0d\u5305\u542bjs \u90e8\u5206 \u4f7f\u7528\u6dd8\u5b9d\u7684 flexible.js \u65b9\u6848 \u6240\u4ee5 1rem = 75px \uff0c\u4f7f\u7528\u5176\u4ed6\u65b9\u6848\u7684rem \u53ef\u4ee5\u81ea\u884c\u66ff\u6362\u76f8\u5173\u4ee3\u7801 html\u90e8\u5206\u7f16\u8bd1\u524d &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[452,1],"tags":[],"topic":[],"class_list":["post-68358","post","type-post","status-publish","format-standard","hentry","category-vue","category-technology"],"_links":{"self":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/comments?post=68358"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68358\/revisions"}],"predecessor-version":[{"id":68359,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68358\/revisions\/68359"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=68358"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=68358"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=68358"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=68358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}