{"id":529,"date":"2020-02-26T21:39:11","date_gmt":"2020-02-26T13:39:11","guid":{"rendered":"https:\/\/blog.cqdefxxx.com\/?p=529"},"modified":"2020-02-26T21:39:11","modified_gmt":"2020-02-26T13:39:11","slug":"vue-%e8%ae%a1%e7%ae%97%e5%b1%9e%e6%80%a7","status":"publish","type":"post","link":"https:\/\/blog.viter.top\/index.php\/2020\/02\/26\/vue-%e8%ae%a1%e7%ae%97%e5%b1%9e%e6%80%a7\/","title":{"rendered":"Vue-\u8ba1\u7b97\u5c5e\u6027"},"content":{"rendered":"<p><strong>\u8ba1\u7b97\u5c5e\u6027<\/strong><br \/>\n<strong>\u590d\u6742\u903b\u8f91,\u6a21\u677f\u96be\u4ee5\u7ef4\u62a4<\/strong><br \/>\n<strong>(1) \u57fa\u7840\u4f8b\u5b50<\/strong><br \/>\n<strong>(2) \u8ba1\u7b97\u7f13\u5b58 VS methods<\/strong><br \/>\n<strong>-\u8ba1\u7b97\u5c5e\u6027\u662f\u57fa\u4e8e\u5b83\u4eec\u7684\u4f9d\u8d56\u8fdb\u884c\u7f13\u5b58\u7684\u3002<\/strong><br \/>\n<strong>-\u8ba1\u7b97\u5c5e\u6027\u53ea\u6709\u5728\u5b83\u7684\u76f8\u5173\u4f9d\u8d56\u53d1\u751f\u6539\u53d8\u65f6\u624d\u4f1a\u91cd\u65b0\u6c42\u503c<\/strong><br \/>\n<strong>(3) \u8ba1\u7b97\u5c5e\u6027 VS watch<\/strong><br \/>\n<strong>- v-model<\/strong><\/p>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;meta charset=\"utf-8\"&gt;\n&lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"&gt;\n&lt;title&gt;Examples&lt;\/title&gt;\n&lt;meta name=\"description\" content=\"\"&gt;\n&lt;meta name=\"keywords\" content=\"\"&gt;\n&lt;link href=\"\" rel=\"stylesheet\"&gt;\n&lt;script src=\"lib\/vue.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div id=\"box\"&gt;\n\n        {{ myname.substring(0,1).toUpperCase()+ myname.substring(1) }}\n        &lt;br\/&gt;\n        \u8ba1\u7b97\u5c5e\u602711111\uff1a{{ mycomputedname }}\n        &lt;br\/&gt;\n        \u65b9\u6cd5111111\uff1a {{ mycomputedmethod() }}\n\n\n\n        &lt;br\/&gt;\n        \u8ba1\u7b97\u5c5e\u60272222\uff1a{{ mycomputedname }}\n        &lt;br\/&gt;\n        \u65b9\u6cd5222222\uff1a {{ mycomputedmethod() }}\n    &lt;\/div&gt;\t\n\n    &lt;script type=\"text\/javascript\"&gt;\n    \t\n      var vm = new Vue({\n        el:\"#box\",\n        data:{\n          myname:\"kerwin\"\n        },\n        methods:{\n          mycomputedmethod(){\n            console.log(\"\u65b9\u6cd5mycomputedmethod\")\n            return this.myname.substring(0,1).toUpperCase()+ this.myname.substring(1)\n          }\n        },\n        computed:{\n          \/\/\u5b9a\u4e49\u4e00\u4e2a\u8ba1\u7b97\u5c5e\u6027\n          mycomputedname(){\n            \/\/1.\u5fc5\u987b\u6709\u8fd4\u56de\u503c\n            \/\/2. \u6bcf\u6b21\u4f9d\u8d56\u6539\u53d8 \uff0c\u8ba1\u7b97\u5c5e\u6027\u4f1a\u91cd\u65b0\u8ba1\u7b97\u4e00\u4e0b\n            \/\/3. \u7f13\u5b58(\u5185\u5b58)\n            console.log(\"\u8ba1\u7b97\u5c5e\u6027mycomputedname\")\n            return this.myname.substring(0,1).toUpperCase()+ this.myname.substring(1)\n          }\n        }\n      })\n    &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h1><\/h1>\n<h1>\u8ba1\u7b97\u5c5e\u6027vswatch-watch<\/h1>\n<pre class=\"pure-highlightjs\"><code class=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;meta charset=\"utf-8\"&gt;\n&lt;meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"&gt;\n&lt;title&gt;Examples&lt;\/title&gt;\n&lt;meta name=\"description\" content=\"\"&gt;\n&lt;meta name=\"keywords\" content=\"\"&gt;\n&lt;link href=\"\" rel=\"stylesheet\"&gt;\n&lt;script src=\"lib\/vue.js\"&gt;&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n    &lt;div id=\"box\"&gt;\n       \n      \n        &lt;!-- &lt;button @click=\"handleClick()\"&gt;\u767b\u5f55&lt;\/button&gt; --&gt;\n        \u5355\u4ef7&lt;input type=\"text\" v-model=\"myprice\"  \/&gt;       \n        \u6570\u91cf&lt;input type=\"text\" v-model=\"mynumber\" \/&gt; \n        \n        &lt;p&gt;{{sum}}&lt;\/p&gt;\n\n    &lt;\/div&gt;\t\n\n    &lt;script type=\"text\/javascript\"&gt;\n    \t\n       \n        \n        var vm = new Vue({\n            el:\"#box\",\n            data:{\n                myprice:100,\n                mynumber:1,\n                sum:0\n            },\n            watch:{\n                myprice(){\n                    console.log(\"price\u6539\u53d8\",this.myprice)\n\n                    if(this.mynumber*this.myprice&gt;1000){\n                        this.sum = this.mynumber*this.myprice;\n                    }else{\n                        this.sum = this.mynumber*this.myprice+100;\n                    }\n                },\n                mynumber(){\n                    console.log(\"number\u6539\u53d8\",this.mynumber)\n\n                    if(this.mynumber*this.myprice&gt;1000){\n                        this.sum = this.mynumber*this.myprice;\n                    }else{\n                        this.sum = this.mynumber*this.myprice+100;\n                    }\n                }\n            }\n        })\n\n    \t\/*\n                \n            1. @input = \"handleInput\" \u9ed8\u8ba4\u4f20\u4e8b\u4ef6\u5bf9\u8c61\n            2. @input = \"handleInput($event)\" \u4f20\u4e8b\u4ef6\u5bf9\u8c61\n\n            3. v-model \u53cc\u5411\u6570\u636e\u7ed1\u5b9a\u6307\u4ee4 -&gt; mvvm (\u53cc\u5411\u6570\u636e\u7ed1\u5b9a) ,\u4f5c\u7528\u4e8e \u8868\u5355\u5143\u7d20\n\n                    \u53cc\u5411\u7ed1\u5b9a\u662f value(checked) &lt;-----&gt; \u72b6\u6001\n         \n            4. data \u4e2d\u5b9a\u4e49 key\u503c \u53eb \u72b6\u6001\u3002\n         *\/\n    &lt;\/script&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8ba1\u7b97\u5c5e\u6027 \u590d\u6742\u903b\u8f91,\u6a21\u677f\u96be\u4ee5\u7ef4\u62a4 (1) \u57fa\u7840\u4f8b\u5b50 (2) \u8ba1\u7b97\u7f13\u5b58 VS methods -\u8ba1\u7b97\u5c5e\u6027\u662f\u57fa\u4e8e\u5b83\u4eec\u7684\u4f9d\u8d56\u8fdb\u884c\u7f13\u5b58\u7684\u3002 &#8230;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[9,10],"_links":{"self":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/529"}],"collection":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/comments?post=529"}],"version-history":[{"count":0,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/posts\/529\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/media?parent=529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/categories?post=529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.viter.top\/index.php\/wp-json\/wp\/v2\/tags?post=529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}