{"id":68367,"date":"2019-08-16T13:03:58","date_gmt":"2019-08-16T05:03:58","guid":{"rendered":"http:\/\/www.xiaoyebailong.com\/?p=68367"},"modified":"2019-08-19T14:49:04","modified_gmt":"2019-08-19T06:49:04","slug":"20%e4%b8%aavue-js%e5%9f%ba%e7%a1%80%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81%ef%bc%881-20%ef%bc%89","status":"publish","type":"post","link":"http:\/\/www.xiaoyebailong.com\/index.php\/2019\/08\/16\/68367.htm","title":{"rendered":"20\u4e2avue.js\u57fa\u7840\u793a\u4f8b\u4ee3\u7801\uff081-20\uff09"},"content":{"rendered":"\n<p><em>1\u3001Vue.js\u5982\u4f55\u83b7\u53d6Url\u67e5\u8be2\u5b57\u7b26\u4e32\u503c\uff1f<\/em><\/p>\n\n\n\n<p>url\u5730\u5740&#8221;\/mypage?q=food&#8221;;&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">this.$route.query.q;<\/pre>\n\n\n\n<p><em>2\u3001Vue.js\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\u793a\u4f8b<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">myvariable.length;<\/pre>\n\n\n\n<p><em>3\u3001Vue.js\u542f\u7528\u7981\u7528\u8f93\u5165\u5b57\u6bb5\u793a\u4f8b<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"app\">  &lt;input type=\"text\" :disabled=\"isDisabled\">  &lt;button @click=\"isDisabled = !isDisabled\">Enable\/Disable&lt;\/button>&lt;\/div>new Vue({  el: '#app',  data: {    isDisabled: false  }})<\/pre>\n\n\n\n<p><em>4\u3001Vue.js\u6eda\u52a8\u5230div\u7684\u5e95\u90e8<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">var divContainer = this.$el.querySelector(\"#divId\");divContainer.scrollTop = divContainer.scrollHeight;<\/pre>\n\n\n\n<p><em>5\u3001Vue.Js\u6eda\u52a8\u5230\u9875\u9762\u793a\u4f8b\u7684\u5e95\u90e8<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">document.body.scrollTop = document.body.scrollHeight;<\/pre>\n\n\n\n<p><em>6\u3001\u9875\u9762\u52a0\u8f7d\u4e2dVue.Js\u8c03\u7528\u51fd\u6570<\/em><br><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">new Vue({    \/\/ ...    methods:{        myFunction: function() {\/\/definition goes here}    },    created: function(){        this.myFunction()    }});<\/pre>\n\n\n\n<p><em>7\u3001Vue.Js Trim \u53bb\u9664\u5b57\u7b26\u4e32\u7a7a\u767d<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;p>{{ text | trim }}&lt;\/p>new Vue({el: '#app',  data: function() {    return {      text: ' This is string having space at both side. '    }  },  filters: {    trim: function(string) {      return string.trim()    }  }});<\/pre>\n\n\n\n<p><em>8\u3001Vue.js Substrin<\/em>g\u622a\u53d6\u5b57\u7b26\u4e32<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"app\">  &lt;p>{{ text | subStr}}&lt;\/p>&lt;\/div>new Vue({el: '#app',  data: function() {    return {      text: ' This is sample string to show trim method. '    }  },  filters: {    subStr: function(string) {      return string.substring(0,15) + '...';        }  }});<\/pre>\n\n\n\n<p><em>9\u3001Vue.Js if else<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"mainDiv\">&lt;\/div>new Vue({    el: \"#mainDiv\",    template: '&lt;div v-if=\"name\">&lt;span v-text=\"name\">&lt;\/span>&lt;\/div>',    data: {       name: \"John\"    } });<\/pre>\n\n\n\n<p><em>10\u3001Vue.js Mouseover\u4e8b\u4ef6<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"myDiv\">    &lt;div v-show=\"active\">Show&lt;\/div>    &lt;div v-on=\"mouseover: mouseOver\">Mouse Hover over to test!&lt;\/div>&lt;\/div>var demo = new Vue({    el: '#myDiv',    data: {        active: false    },    methods: {        mouseOver: function(){            this.active = !this.active;           }    }});<\/pre>\n\n\n\n<p><em>11\u3001Vue.js\u5f3a\u5236\u91cd\u65b0\u52a0\u8f7d\u91cd\u65b0\u6e32\u67d3\u9875\u9762\u89c6\u56fe\u793a\u4f8b<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">vm.$forceUpdate();<\/pre>\n\n\n\n<p><em>12\u3001Vue.Js Focus\u8f93\u5165\u5143\u7d20\u793a\u4f8b<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">Vue.directive('focus', {    inserted: function (el) {        el.focus()    }});<\/pre>\n\n\n\n<p><em>13\u3001Vue.JS watch\u76d1\u542c\u6539\u53d8\u503c\u4e8b\u4ef6<\/em><br><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"app\">    {{ message }}    &lt;span>{{myVal}}&lt;\/span>&lt;br \/>    &lt;input v-model=\"myVal\">&lt;\/div>new Vue({    el: '#app',    data: {        message: 'On change event example',        myValue: 50    },    watch: {        'myValue': function(val, preVal){        if (val &lt; 50) {            this.message= 'Value is less than 50';        }else{          this.message= 'Value is greater than 50';        }      }    }})<\/pre>\n\n\n\n<p><em>14\u3001Vue.JS\u68c0\u67e5Object\u6216Array\u662f\u5426\u4e3a\u7a7a\u793a\u4f8b<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;ul id=\"exampleApp\">  &lt;li v-if=\"!items.length\">No item found&lt;\/li>  &lt;li v-for=\"item in items\">    &lt;!--do whatever you want-->  &lt;\/li>&lt;\/ul>var exampleApp = new Vue({  el: '#exampleApp',  data: {    items: []  }});<\/pre>\n\n\n\n<p><em>15\u3001Vue.js\u83b7\u53d6\u6570\u7ec4\u957f\u5ea6<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;ul id=\"exampleApp\">  &lt;li v-if=\"items.length\">Object Length = {{items.length}}&lt;\/li>  &lt;li v-for=\"item in items\">    {{ item.fruit }}  &lt;\/li>&lt;\/ul>var exampleApp = new Vue({  el: '#exampleApp',  data: {    items: [      { fruit: 'Mango' },      { fruit: 'Apple' },      { fruit: 'Banana' }    ]  }});<\/pre>\n\n\n\n<p><em>16\u3001Vue.js\u6570\u7ec4push| \u6dfb\u52a0\u5143\u7d20\u5230\u6570\u7ec4\u793a\u4f8b<\/em><br><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"app\">   &lt;h1>List&lt;\/h1>  &lt;div v-for=\"(listItem, index) in list\">    &lt;input v-model=\"listItem.a\" value=\"{{listItem.a}}\">  &lt;\/div>  &lt;button @click=\"addList\">    Add New List  &lt;\/button>  &lt;b>{{ list }}&lt;\/b>&lt;\/div> new Vue({  el: '#app',  data: {    list: [{a: 'Hello World!' }]  },  methods: {    addList: function () {      this.list.push({ a: 'Hello World!' });    }    }});<\/pre>\n\n\n\n<p><em>17\u3001Vue.js\u4eceArray \u4e2d\u5220\u9664\u5143\u7d20<\/em><br><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"app\">   &lt;h1>List&lt;\/h1>  &lt;div v-for=\"(listItem, index) in list\">    &lt;input v-model=\"listItem.a\" value=\"{{listItem.a}}\">    &lt;button @click=\"deleteList(index)\"> Delete List&lt;\/button>  &lt;\/div>  &lt;button @click=\"addList\">Add New List&lt;\/button>  &lt;b>{{ list }}&lt;\/b>&lt;\/div> new Vue({  el: '#app',  data: {    list: [{a: 'Hello World!' }]  },  methods: {    addList: function () {      this.list.push({ a: 'Hello World!' });    },    deleteList: function (index) {      this.list.splice(index, 1);    }  }});<\/pre>\n\n\n\n<p><em>18\u3001Vue.Js\u8bbe\u7f6etextarea\u503c<\/em><br><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"app\">   &lt;h1>TextArea&lt;\/h1>   &lt;textarea v-model=\"myTextarea\" placeholder=\"add multiple lines\">&lt;\/textarea>&lt;\/div> new Vue({  el: '#app',  data: {    myTextarea: ['Hello World!']  } });<\/pre>\n\n\n\n<p><em>&nbsp;19\u3001Vue.Js\u83b7\u53d6\u6587\u672c\u533a\u57df\u503c<\/em><br><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"app\">   &lt;h1>TextArea&lt;\/h1>   &lt;textarea v-model=\"myTextarea\" placeholder=\"add multiple lines\">&lt;\/textarea>  &lt;p>TextArea Value = {{myTextarea}}&lt;\/p>&lt;\/div>new Vue({  el: '#app',  data: {    myTextarea: ['Hello World!']  }});<\/pre>\n\n\n\n<p><em>20\u3001\u5982\u4f55\u5728Vue.JS\u793a\u4f8b\u4e2d\u4f7f\u7528setTimeOut<\/em><\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;div id=\"app\">   {{message}}&lt;\/div>new Vue({  el: '#app',  data: {    message:\"Hello World!\"  },  methods:{    testFunction: function () {      var v = this;      setTimeout(function () {        v.message = \"Hi Vue!\";    }, 3000);   }  }, mounted () {  this.testFunction() }});<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1\u3001Vue.js\u5982\u4f55\u83b7\u53d6Url\u67e5\u8be2\u5b57\u7b26\u4e32\u503c\uff1f url\u5730\u5740&#8221;\/mypage?q=food&#8221;;&nbsp; 2\u3001Vue.js\u83b7\u53d6\u5b57\u7b26\u4e32\u957f\u5ea6\u793a\u4f8b 3\u3001Vue.js\u542f\u7528\u7981\u7528\u8f93\u5165\u5b57\u6bb5\u793a\u4f8b 4\u3001Vue.js\u6eda\u52a8\u5230div\u7684\u5e95\u90e8 5&#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-68367","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\/68367","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=68367"}],"version-history":[{"count":1,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68367\/revisions"}],"predecessor-version":[{"id":68368,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/posts\/68367\/revisions\/68368"}],"wp:attachment":[{"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/media?parent=68367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/categories?post=68367"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/tags?post=68367"},{"taxonomy":"topic","embeddable":true,"href":"http:\/\/www.xiaoyebailong.com\/index.php\/wp-json\/wp\/v2\/topic?post=68367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}