{"id":977,"date":"2023-03-23T22:41:43","date_gmt":"2023-03-23T14:41:43","guid":{"rendered":""},"modified":"2023-03-23T22:41:43","modified_gmt":"2023-03-23T14:41:43","slug":"Vue.js \u76d1\u542c\u5c5e\u6027","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/977.html","title":{"rendered":"Vue.js \u76d1\u542c\u5c5e\u6027"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

Vue.js \u76d1\u542c\u5c5e\u6027<\/h1>\n<\/p><\/div>\n
\n Vue.js\u76d1\u89c6\u5668\u6216\u76d1\u542c\u5c5e\u6027\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u4fa6\u542c\u7ec4\u4ef6\u6570\u636e\u5e76\u5728\u66f4\u6539\u7279\u5b9a\u5c5e\u6027\u65f6\u8fd0\u884c\u3002 watcher\u6216\u76d1\u542c\u5c5e\u6027\u662fVue.js\u7684\u4e00\u9879\u72ec\u7279\u529f\u80fd\uff0c\u53ef\u8ba9\u60a8\u5173\u6ce8\u7ec4\u4ef6\u72b6\u6001\u7684\u4e00\u4e2a\u5c5e\u6027\u5e76\u5728\u8be5\u5c5e\u6027\u503c\u66f4\u6539\u65f6\u8fd0\u884c\u4e00\u4e2a\u51fd\u6570\u3002\n <\/div>\n
\n \u8ba9\u6211\u4eec\u4e3e\u4e2a\u4f8b\u5b50\u6765\u770b\u4e00\u4e0b\u5e76\u5b66\u4e60\u5173\u4e8eVueJS\u4e2d\u7684\u76d1\u542c\u5c5e\u6027\u3002\u8bf7\u53c2\u9605\u4ee5\u4e0b\u793a\u4f8b\u4ee5\u4e86\u89e3\u76d1\u89c6\u7a0b\u5e8f\u6216\u76d1\u89c6\u5c5e\u6027\u7684\u6982\u5ff5\u3002\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span>
   <head><\/span>
      <title><\/span>Vue.js Watch Property<\/title><\/span>
      <link rel=\"stylesheet\" href=\"index.css\">
        <script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue\/dist\/vue.js\"><\/script><\/span>
    <\/head><\/span>
    <body><\/span>
    <div id = \"wat_pro\">
         Kilometers : <input type = \"text\" v-model = \"kilometers\"><br\/>
         Meters : <input type = \"text\" v-model = \"meters\">
      <\/div><\/span>
      <script src=\"index.js\"><\/script><\/span>
   <\/body><\/span>
<\/html><\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n Index.js\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 var vm = new Vue({
            el: '#wat_pro',
            data: {
               kilometers : 0,
               meters:0
            },
            methods: {
            },
            computed :{
            },
            watch : {
               kilometers:function(val) {
                  this.kilometers = val;
                  this.meters = val * 1000;
               },
               meters : function (val) {
                  this.kilometers = val\/ 1000;
                  this.meters = val;
               }
            }
         })
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8ba9\u6211\u4eec\u4f7f\u7528\u7b80\u5355\u7684
\n CSS \u6587\u4ef6\u4f7f\u8f93\u51fa\u66f4\u5177\u5438\u5f15\u529b\u3002\n <\/div>\n
\n Index.css\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 html, body {
    margin: 5px;
    padding: 0;
}
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u7a0b\u5e8f\u6267\u884c\u540e\uff0c\u60a8\u5c06\u770b\u5230\u4ee5\u4e0b\u8f93\u51fa:\n <\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n

Vue.js \u76d1\u542c\u5c5e\u6027_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n

\n \u60a8\u53ef\u4ee5\u770b\u5230\u8f93\u51fa\u5728\u5176\u6587\u672c\u6846\u4e2d\u5177\u67090\u6761\u76ee\u3002\u5982\u679c\u5728\"\u516c\u91cc\"\u6587\u672c\u6846\u4e2d\u8f93\u5165\u4e00\u4e9b\u503c\uff0c\u5219\u53ef\u4ee5\u5728\"\u7c73\"\u6587\u672c\u6846\u4e2d\u770b\u5230\u66f4\u6539\uff0c\u53cd\u4e4b\u4ea6\u7136\u3002\u8ba9\u6211\u4eec\u8f93\u516550\u82f1\u91cc\u4e3a\u5355\u4f4d\u7684\u6587\u672c\u6846\uff0c\u7136\u540e\u67e5\u770b\u7ed3\u679c\u3002\n <\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n

Vue.js \u76d1\u542c\u5c5e\u6027_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c2\u5f20 <\/p>\n

\n \u73b0\u5728\uff0c\u5728\u4eea\u8868\u6587\u672c\u6846\u4e2d\u8f93\u5165\u4e00\u4e9b\u503c\uff0c\u7136\u540e\u5728\u516c\u91cc\u6587\u672c\u6846\u4e2d\u67e5\u770b\u66f4\u6539\u3002\u8ba9\u6211\u4eec\u5728\u4eea\u8868\u6587\u672c\u6846\u4e2d\u8f93\u51655\uff0c\u7136\u540e\u5728\u8f93\u51fa\u4e2d\u67e5\u770b\u7ed3\u679c\u3002\n <\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n

Vue.js \u76d1\u542c\u5c5e\u6027_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c3\u5f20 <\/p>\n

\u793a\u4f8b\u8bf4\u660e<\/h3>\n
\n \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e24\u4e2a\u6587\u672c\u6846\uff0c\u4e00\u4e2a\u5e26\u6709\u516c\u91cc\uff0c\u53e6\u4e00\u4e2a\u4e0e\u7c73\u3002\u6211\u4eec\u5df2\u7ecf\u5728data\u5c5e\u6027\u4e2d\u5c06\u516c\u91cc\u548c\u7c73\u7684\u4e24\u4e2a\u6587\u672c\u6846\u521d\u59cb\u5316\u4e3a0\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u76d1\u89c6\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u5177\u6709\u516c\u91cc\u548c\u7c73\u4e24\u4e2a\u529f\u80fd\u3002\u5728\u8fd9\u4e24\u4e2a\u51fd\u6570\u4e2d\uff0c\u90fd\u5b8c\u6210\u4e86\u4ece\u516c\u91cc\u5230\u7c73\u7684\u8f6c\u6362\u4ee5\u53ca\u4ece\u7c73\u5230\u516c\u91cc\u7684\u8f6c\u6362\u3002\n <\/div>\n
\n \u5728\u4efb\u4f55\u4e00\u4e2a\u6587\u672c\u6846\u5185\u8f93\u5165\u503c\u65f6\uff0c\u65e0\u8bba\u54ea\u4e2a\u66f4\u6539\uff0c\u76d1\u542c\u5c5e\u6027\u90fd\u5c06\u540c\u65f6\u66f4\u65b0\u4e24\u4e2a\u6587\u672c\u6846\u3002 \u3002\u60a8\u4e0d\u5fc5\u5206\u914d\u4efb\u4f55\u4e8b\u4ef6\u6216\u7b49\u5f85\u5176\u66f4\u6539\u5e76\u8fdb\u884c\u989d\u5916\u7684\u9a8c\u8bc1\u5de5\u4f5c\u3002 \u76d1\u542c\u5c5e\u6027\u8d1f\u8d23\u4f7f\u7528\u5728\u5404\u4e2a\u51fd\u6570\u4e2d\u5b8c\u6210\u7684\u8ba1\u7b97\u6765\u66f4\u65b0\u6587\u672c\u6846\u3002\n <\/div>\n

Vue.js\u8ba1\u7b97\u4e0e\u76d1\u89c6\u5c5e\u6027<\/h3>\n
\n \u5982\u679c\u60a8\u6bd4\u8f83Vue\u3002 js\u4f7f\u7528
\n Vue.js \u76d1\u89c6\u5c5e\u6027\u8ba1\u7b97\u5c5e\u6027\uff0c\u7136\u540eVue.js\u76d1\u89c6\u5c5e\u6027\u63d0\u4f9b\u4e86\u4e00\u79cd\u89c2\u5bdf\u548c\u505a\u51fa\u53cd\u5e94\u7684\u66f4\u901a\u7528\u65b9\u6cd5\u6570\u636e\u66f4\u6539\u3002\n <\/div>\n
\n \u5982\u679c\u60a8\u9700\u8981\u6839\u636e\u5176\u4ed6\u6570\u636e\u6765\u66f4\u6539\u67d0\u4e9b\u6570\u636e\uff0c\u5219\u4f7f\u7528\u76d1\u542c\u5c5e\u6027\u975e\u5e38\u7b80\u5355\u660e\u4e86\uff0c\u5c24\u5176\u662f\u5f53\u60a8\u6765\u81eaAngularJS\u80cc\u666f\u65f6\u3002\u4f46\u662f\uff0c\u6700\u597d\u4f7f\u7528\u8ba1\u7b97\u5c5e\u6027\u800c\u4e0d\u662f\u547d\u4ee4\u5f0f\u76d1\u89c6\u56de\u8c03\u3002\n <\/div>\n
\n \u8ba9\u6211\u4eec\u4e3e\u4e2a\u4f8b\u5b50\uff0c\u5c06\u5176\u4e0e\u76d1\u542c\u5c5e\u6027\u548c\u8ba1\u7b97\u5c5e\u6027\u8fdb\u884c\u6bd4\u8f83\u3002\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span>
   <head><\/span>
      <title><\/span>Vue.js Watch Property<\/title><\/span>
      <link rel=\"stylesheet\" href=\"index.css\">
        <script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue\/dist\/vue.js\"><\/script><\/span>
    <\/head><\/span>
    <body><\/span>
    <div id=\"eg_1\">{{ fullName }}<\/div><\/span>
      <script src=\"index.js\"><\/script><\/span>
   <\/body><\/span>
<\/html><\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n Index.js\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 var vm = new Vue({
  el: '#eg_1',
  data: {
    firstName: 'Alex',
    lastName: 'Panda',
    fullName: 'Alex Panda'
  },
  watch: {
    firstName: function (val) {
      this.fullName = val + ' ' + this.lastName
    },
    lastName: function (val) {
      this.fullName = this.firstName + ' ' + val
    }
  }
})
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n

Vue.js \u76d1\u542c\u5c5e\u6027_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c4\u5f20 <\/p>\n

\n \u60a8\u53ef\u4ee5\u770b\u5230\u4e0a\u9762\u7684\u4ee3\u7801\u662f\u547d\u4ee4\u6027\u7684\u548c\u91cd\u590d\u7684\u3002\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u5c06\u5176\u4e0e\u8ba1\u7b97\u7684\u5c5e\u6027\u793a\u4f8b\u8fdb\u884c\u6bd4\u8f83:\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span>
   <head><\/span>
      <title><\/span>Vue.js Computed Property<\/title><\/span>
      <link rel=\"stylesheet\" href=\"index.css\">
        <script src=\"https:\/\/cdn.jsdelivr.net\/npm\/vue\/dist\/vue.js\"><\/script><\/span>
    <\/head><\/span>
    <body><\/span>
    <div id=\"eg_2\">{{ fullName }}<\/div><\/span>
      <script src=\"index.js\"><\/script><\/span>
   <\/body><\/span>
<\/html><\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n Index.js\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 var vm = new Vue({
  el: '#eg_2',
  data: {
    firstName: 'Alex',
    lastName: 'Panda'
  },
  computed: {
    fullName: function () {
      return this.firstName + ' ' + this.lastName
    }
  }
})
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n

Vue.js \u76d1\u542c\u5c5e\u6027_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c5\u5f20 <\/p>\n

\n \u60a8\u53ef\u4ee5\u770b\u5230\u4e24\u4e2a\u793a\u4f8b\u7ed9\u51fa\u7684\u7ed3\u679c\u76f8\u540c\uff0c\u4f46\u662f\u7b2c\u4e8c\u4e2a\u793a\u4f8b\"\u8ba1\u7b97\u673a\u5c5e\u6027\"\u793a\u4f8b\u66f4\u597d\u800c\u7b80\u6d01\u3002\n <\/div>\n
\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Vue.js \u76d1\u542c\u5c5e\u6027zh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[122],"tags":[],"class_list":["post-977","post","type-post","status-publish","format-standard","hentry","category-vuejc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/977"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=977"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/977\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}