{"id":1955,"date":"2017-04-06T18:42:15","date_gmt":"2017-04-06T10:42:15","guid":{"rendered":"http:\/\/www.qdabc.cn\/?p=1955"},"modified":"2017-04-06T18:42:15","modified_gmt":"2017-04-06T10:42:15","slug":"vue%e5%85%a5%e9%97%a8-%e6%a8%a1%e7%89%88%e8%af%ad%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.qdabc.cn\/?p=1955","title":{"rendered":"Vue\u5165\u95e8 &#8211; \u6a21\u7248\u8bed\u6cd5"},"content":{"rendered":"<h1 id=\"1-\u63d2\u503c\">1 \u63d2\u503c<\/h1>\n<h2 id=\"11-\u6587\u672c\"><a name=\"t1\"><\/a>1.1 \u6587\u672c<\/h2>\n<ol>\n<li>\u4f7f\u7528\u53cc\u5927\u62ec\u53f7<code>{{ \u8868\u8fbe\u5f0f}}<\/code>\u8fdb\u884c\u63d2\u503c\uff0c\u8868\u793a\u5c06\u6570\u636e\u4e0eDOM\u8282\u70b9\u7ed1\u5b9a\u3002\u6570\u636e\u6539\u53d8\u65f6\uff0c\u8282\u70b9\u4e5f\u76f8\u5e94\u6539\u53d8\u3002<\/li>\n<li>\u4f7f\u7528v-once\u6267\u884c\u4e00\u6b21\u6027\u7684\u63d2\u503c\uff0c\u6570\u636e\u6539\u53d8\u65f6\u63d2\u503c\u5185\u5bb9\u4e0d\u4f1a\u66f4\u65b0\u3002<code>&lt;span v-once&gt;{{ msg }}&lt;\/span&gt;<\/code><\/li>\n<\/ol>\n<h2 id=\"12-\u7eafhtml\"><a name=\"t2\"><\/a>1.2 \u7eafHTML<\/h2>\n<ol>\n<li>\u53cc\u5927\u62ec\u53f7\u4f1a\u5c06\u6570\u636e\u7ffb\u8bd1\u4e3a\u7eaf\u6587\u672c\uff0c\u82e5\u60f3\u8f93\u51faHTML\uff0c\u9700\u4f7f\u7528v-html\u6307\u4ee4\u3002\n<ul>\n<li><code>&lt;div v-html=\"html\"&gt;&lt;\/div&gt;<\/code><\/li>\n<\/ul>\n<\/li>\n<li>\u8be5\u6307\u4ee4\u5185\u90e8\u5b9e\u73b0\u662f\u66f4\u65b0\u5143\u7d20\u7684 innerHTML\uff0c\u6240\u4ee5\u5bbf\u4e3b\u5143\u7d20\u7684\u539finnerHTML\u5185\u5bb9\u90fd\u4f1a\u88ab\u79fb\u9664\u3002<\/li>\n<li>\u5185\u5bb9\u6309\u666e\u901a HTML \u63d2\u5165 &#8211; \u4e0d\u4f1a\u4f5c\u4e3a Vue \u6a21\u677f\u8fdb\u884c\u7f16\u8bd1\u3002<\/li>\n<li>\u5c3d\u91cf\u522b\u7528\uff0c\u4e0d\u5b89\u5168\u3002<\/li>\n<\/ol>\n<hr \/>\n<h1 id=\"2-\u5c5e\u6027\"><a name=\"t3\"><\/a>2 \u5c5e\u6027<\/h1>\n<ol>\n<li>\u5c5e\u6027\u7ed1\u5b9a<code>v-bind:propName=\"\u8868\u8fbe\u5f0f\"<\/code>\uff0c\u5982<code>v-bind:disable=\"false\"<\/code>\u3002<\/li>\n<li>\u5c5e\u6027\u7ed1\u5b9a\u7b80\u5199<code>:propName=\"\u8868\u8fbe\u5f0f\"<\/code>\uff0c\u5982<code>v-bind:disable=\"isShow\"<\/code>\u3002<\/li>\n<li>\u4e8b\u4ef6\u7ed1\u5b9a<code>v-on:click=\"func\"<\/code>\u3002<\/li>\n<li>\u4e8b\u4ef6\u7ed1\u5b9a\u7b80\u5199<code>@click=\"func\"<\/code>\u3002<\/li>\n<\/ol>\n<hr \/>\n<h1 id=\"3-\u6307\u4ee4\"><a name=\"t4\"><\/a>3 \u6307\u4ee4<\/h1>\n<ol>\n<li>\u6307\u4ee4\u662f\u4ee5\u201dv-\u201c\u4e3a\u524d\u7f00\u7684\u7279\u6b8a\u5c5e\u6027\u3002<\/li>\n<li>\u6307\u4ee4\u5c5e\u6027\u7684\u503c\u9884\u671f\u662f\u5355\u4e00 JavaScript \u8868\u8fbe\u5f0f\uff08\u9664\u4e86 v-for\uff09\u3002<\/li>\n<li>\u6307\u4ee4\u7684\u804c\u8d23\u5c31\u662f\u5f53\u5176\u8868\u8fbe\u5f0f\u7684\u503c\u6539\u53d8\u65f6\u76f8\u5e94\u5730\u5c06\u67d0\u4e9b\u884c\u4e3a\u5e94\u7528\u5230 DOM \u4e0a\u3002<\/li>\n<li>\u5e38\u7528\u5185\u7f6e\u6307\u4ee4\u5982v-if\uff0cv-for\uff0cv-bind\uff0cv-on\u7b49\u3002<\/li>\n<\/ol>\n<h2 id=\"31-\u6307\u4ee4\u53c2\u6570\"><a name=\"t5\"><\/a>3.1 \u6307\u4ee4\u53c2\u6570<\/h2>\n<ol>\n<li>\u4e00\u4e2a\u6307\u4ee4\u80fd\u63a5\u53d7\u4e00\u4e2a\u53c2\u6570\u3002<\/li>\n<li>\u53c2\u6570\u5728\u6307\u4ee4\u540e\u4ee5<code>:<\/code>\u58f0\u660e\uff0c\u5982<code>v-bind:href=\"url\"<\/code>\uff0c<code>v-on:click=\"showTime\"<\/code>\u3002<\/li>\n<\/ol>\n<h2 id=\"32-\u6307\u4ee4\u4fee\u9970\u7b26\"><a name=\"t6\"><\/a>3.2 \u6307\u4ee4\u4fee\u9970\u7b26<\/h2>\n<ol>\n<li>\u4fee\u9970\u7b26\u5728\u6307\u4ee4(\u53c2\u6570)\u540e\u4ee5<code>.<\/code>\u58f0\u660e\uff0c\u5982<code>v-on:click.prevent=\"show\"<\/code>\uff0c\u8fd9\u91ccprevent\u4ee3\u8868\u539f\u751fevent\u7684preventDefault\u3002<\/li>\n<li>\u4e00\u4e2a\u6307\u4ee4\u53ef\u6302\u591a\u4e2a\u4fee\u9970\u7b26\u3002<code>&lt;a v-on:click.stop.prevent=\"doThat\"&gt;&lt;\/a&gt;<\/code><\/li>\n<\/ol>\n<p><strong>\u4e8b\u4ef6\u4fee\u9970\u7b26\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u4fee\u9970\u7b26<\/th>\n<th>\u539f\u751f<\/th>\n<th>\u4f5c\u7528<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>.stop<\/td>\n<td>event.stopPropagation();<\/td>\n<td>\u963b\u6b62\u5355\u51fb\u4e8b\u4ef6\u5192\u6ce1<\/td>\n<\/tr>\n<tr>\n<td>.prevent<\/td>\n<td>event.preventDefault()<\/td>\n<td>\u53d6\u6d88\u4e8b\u4ef6\u7684\u9ed8\u8ba4\u52a8\u4f5c\u3002<\/td>\n<\/tr>\n<tr>\n<td>.capture<\/td>\n<td>el.addEventListener([event-name],[callback],[use-capture]);<\/td>\n<td>\u6dfb\u52a0\u4e8b\u4ef6\u4fa6\u542c\u5668\u65f6\u4f7f\u7528\u4e8b\u4ef6\u6355\u83b7\u6a21\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>.self<\/td>\n<td>~<\/td>\n<td>\u53ea\u5f53\u4e8b\u4ef6\u5728\u8be5\u5143\u7d20\u672c\u8eab\uff08\u800c\u4e0d\u662f\u5b50\u5143\u7d20\uff09\u89e6\u53d1\u65f6\u89e6\u53d1\u56de\u8c03<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u4f7f\u7528\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre class=\"prettyprint\"><code class=\"language-html hljs  has-numbering\"><span class=\"hljs-comment\">&lt;!-- \u963b\u6b62\u5355\u51fb\u4e8b\u4ef6\u5192\u6ce1 --&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">a<\/span> <span class=\"hljs-attribute\">v-on:click.stop<\/span>=<span class=\"hljs-value\">\"doThis\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">a<\/span>&gt;<\/span>\r\n\r\n<span class=\"hljs-comment\">&lt;!-- \u63d0\u4ea4\u4e8b\u4ef6\u4e0d\u518d\u91cd\u8f7d\u9875\u9762 --&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">form<\/span> <span class=\"hljs-attribute\">v-on:submit.prevent<\/span>=<span class=\"hljs-value\">\"onSubmit\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">form<\/span>&gt;<\/span>\r\n\r\n<span class=\"hljs-comment\">&lt;!-- \u4fee\u9970\u7b26\u53ef\u4ee5\u4e32\u8054 --&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">a<\/span> <span class=\"hljs-attribute\">v-on:click.stop.prevent<\/span>=<span class=\"hljs-value\">\"doThat\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">a<\/span>&gt;<\/span>\r\n\r\n<span class=\"hljs-comment\">&lt;!-- \u53ea\u6709\u4fee\u9970\u7b26 --&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">form<\/span> <span class=\"hljs-attribute\">v-on:submit.prevent<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">form<\/span>&gt;<\/span>\r\n\r\n<span class=\"hljs-comment\">&lt;!-- \u6dfb\u52a0\u4e8b\u4ef6\u4fa6\u542c\u5668\u65f6\u4f7f\u7528\u4e8b\u4ef6\u6355\u83b7\u6a21\u5f0f --&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div<\/span> <span class=\"hljs-attribute\">v-on:click.capture<\/span>=<span class=\"hljs-value\">\"doThis\"<\/span>&gt;<\/span>...<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">div<\/span>&gt;<\/span>\r\n\r\n<span class=\"hljs-comment\">&lt;!-- \u53ea\u5f53\u4e8b\u4ef6\u5728\u8be5\u5143\u7d20\u672c\u8eab\uff08\u800c\u4e0d\u662f\u5b50\u5143\u7d20\uff09\u89e6\u53d1\u65f6\u89e6\u53d1\u56de\u8c03 --&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;<span class=\"hljs-title\">div<\/span> <span class=\"hljs-attribute\">v-on:click.self<\/span>=<span class=\"hljs-value\">\"doThat\"<\/span>&gt;<\/span>...<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-title\">div<\/span>&gt;<\/span><\/code><\/pre>\n<hr \/>\n<h1 id=\"4-\u8fc7\u6ee4\u5668\u7ba1\u9053\"><a name=\"t7\"><\/a>4 \u8fc7\u6ee4\u5668(\u7ba1\u9053)<\/h1>\n<ol>\n<li>\u8fc7\u6ee4\u5668\u5373\u662fangular\u4e2d\u7684\u7ba1\u9053\uff0c\u4e3b\u8981\u7528\u4e8e\u6587\u672c\u683c\u5f0f\u5316\u3002<\/li>\n<li>\u53ea\u80fd\u5728\u63d2\u503c\u548c\u5c5e\u6027\u7ed1\u5b9a\u4e2d\u4f7f\u7528\u8fc7\u6ee4\u5668\uff0c\u5176\u4ed6\u60c5\u51b5\u4f7f\u7528\u8ba1\u7b97\u5c5e\u6027\u3002\n<ul>\n<li>{{ message | capitalize }}<\/li>\n<li><code>&lt;div v-bind:id=\"rawId | formatId\"&gt;&lt;\/div&gt;<\/code><\/li>\n<\/ul>\n<\/li>\n<li>\u8fc7\u6ee4\u5668\u53ef\u4ee5\u4e32\u8054\uff1a\n<ul>\n<li>{{ message | filterA | filterB }}<\/li>\n<\/ul>\n<\/li>\n<li>\u8fc7\u6ee4\u5668\u662f JavaScript \u51fd\u6570\uff0c\u56e0\u6b64\u53ef\u4ee5\u63a5\u53d7\u53c2\u6570\uff1a\n<ul>\n<li>{{ message | filterA(\u2018arg1\u2019, arg2) }}<\/li>\n<li>\u5b57\u7b26\u4e32arg1\u5c06\u4f20\u7ed9\u8fc7\u6ee4\u5668\u4f5c\u4e3a\u7b2c\u4e8c\u4e2a\u53c2\u6570\uff0carg2 \u8868\u8fbe\u5f0f\u7684\u503c\u5c06\u88ab\u6c42\u503c\u7136\u540e\u4f20\u7ed9\u8fc7\u6ee4\u5668\u4f5c\u4e3a\u7b2c\u4e09\u4e2a\u53c2\u6570\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h2 id=\"41-\u81ea\u5b9a\u4e49\u8fc7\u6ee4\u5668\"><a name=\"t8\"><\/a>4.1 \u81ea\u5b9a\u4e49\u8fc7\u6ee4\u5668<\/h2>\n<p>\u5728Vue\u5b9e\u4f8b\u7684option\u4e2d\uff0c\u6216Vue\u7ec4\u4ef6\u5bf9\u8c61\u4e2d\uff1a<\/p>\n<pre class=\"prettyprint\"><code class=\"language-javascript hljs  has-numbering\"><span class=\"hljs-comment\">\/\/...<\/span>\r\nfilter:{\r\n    capitalize:<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span><span class=\"hljs-params\">(value,[arg1],[arg2]...)<\/span>{<\/span>\r\n        <span class=\"hljs-comment\">\/\/...<\/span>\r\n        <span class=\"hljs-keyword\">return<\/span> xxx;\r\n    }\r\n}<\/code><\/pre>\n<p class=\"post-copyright\">\u6b22\u8fce\u5206\u4eab\u672c\u6587\uff0c\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u51fa\u5904\uff1a<a href=\"http:\/\/www.qdabc.cn\">\u524d\u7aefABC<\/a> &raquo; <a href=\"http:\/\/www.qdabc.cn\/?p=1955\">Vue\u5165\u95e8 &#8211; \u6a21\u7248\u8bed\u6cd5<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>1 \u63d2\u503c 1.1 \u6587\u672c \u4f7f\u7528\u53cc\u5927\u62ec\u53f7{{ \u8868\u8fbe\u5f0f}}\u8fdb\u884c\u63d2\u503c\uff0c\u8868\u793a\u5c06\u6570\u636e\u4e0eDOM\u8282\u70b9\u7ed1\u5b9a\u3002\u6570\u636e\u6539\u53d8\u65f6\uff0c\u8282\u70b9\u4e5f\u76f8\u5e94\u6539\u53d8\u3002 \u4f7f\u7528v-once\u6267\u884c\u4e00\u6b21\u6027\u7684\u63d2\u503c\uff0c\u6570\u636e\u6539\u53d8\u65f6\u63d2\u503c\u5185\u5bb9\u4e0d\u4f1a\u66f4\u65b0\u3002&lt;span  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[186],"tags":[26],"_links":{"self":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1955"}],"collection":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1955"}],"version-history":[{"count":1,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1955\/revisions"}],"predecessor-version":[{"id":1956,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1955\/revisions\/1956"}],"wp:attachment":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1955"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}