{"id":987,"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 \u6e32\u67d3\u529f\u80fd","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/987.html","title":{"rendered":"Vue.js \u6e32\u67d3\u529f\u80fd"},"content":{"rendered":"


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

\n

Vue.js \u6e32\u67d3\u529f\u80fd<\/h1>\n<\/p><\/div>\n
\n Vue.js\u5efa\u8bae\u6211\u4eec\u4f7f\u7528\u6a21\u677f\u6765\u6784\u5efaHTML\u3002\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06render\u51fd\u6570\u7528\u4f5c\u6a21\u677f\u7684\u66f4\u63a5\u8fd1\u7f16\u8bd1\u5668\u7684\u66ff\u4ee3\u65b9\u6cd5\u3002\n <\/div>\n
\n Vue.js\u6e32\u67d3\u51fd\u6570\u4e5f\u4e0eVue.js\u7ec4\u4ef6\u4e00\u8d77\u4f7f\u7528\u3002\u5927\u591a\u6570\u65f6\u5019\uff0crender\u51fd\u6570\u662f\u7531Vue.js\u7f16\u8bd1\u5668\u521b\u5efa\u7684\u3002\u5f53\u60a8\u5728\u7ec4\u4ef6\u4e0a\u6307\u5b9a\u6a21\u677f\u65f6\uff0c\u8be5\u6a21\u677f\u7684\u5185\u5bb9\u7531Vue.js\u7f16\u8bd1\u5668\u5904\u7406\uff0c\u8be5\u7f16\u8bd1\u5668\u5c06\u8fd4\u56de\u6e32\u67d3\u529f\u80fd\u3002\u5448\u73b0\u51fd\u6570\u672c\u8d28\u4e0a\u8fd4\u56de\u4e00\u4e2a\u865a\u62dfDOM\u8282\u70b9\uff0c\u8be5\u8282\u70b9\u5c06\u7531Vue.js\u5728\u60a8\u7684\u6d4f\u89c8\u5668DOM\u4e2d\u5448\u73b0\u3002\n <\/div>\n

\u4ec0\u4e48\u662f\u865a\u62df\u6587\u6863\u5bf9\u8c61\u6a21\u578b\u6216\" DOM\"\uff1f<\/h3>\n
\n \u865a\u62dfDOM\u5141\u8bb8
\n Vue.js \u5728\u66f4\u65b0\u6d4f\u89c8\u5668\u4e4b\u524d\u5c06\u5176\u7ec4\u4ef6\u5448\u73b0\u5728\u5176\u5185\u5b58\u4e2d\u3002\u8fd9\u4f7f\u4e00\u5207\u53d8\u5f97\u66f4\u5feb\uff0c\u56e0\u4e3a\u5b83\u53ea\u9700\u8981\u4e0e\u6d4f\u89c8\u5668\u8fdb\u884c\u5c11\u91cf\u4ea4\u4e92\u5373\u53ef\u3002 Vue.js\u66f4\u65b0\u6d4f\u89c8\u5668DOM\u65f6\uff0c\u4f1a\u5c06\u66f4\u65b0\u7684\u865a\u62dfDOM\u4e0e\u4e0a\u4e00\u4e2a\u865a\u62dfDOM\u8fdb\u884c\u6bd4\u8f83\uff0c\u5e76\u4f7f\u7528\u4fee\u6539\u540e\u7684\u90e8\u5206\u66f4\u65b0\u5b9e\u9645DOM\u3002\u8fd9\u6837\u4fbf\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002\n <\/div>\n
\n \u8ba9\u6211\u4eec\u4ee5\u4e00\u4e2a\u7b80\u5355\u7ec4\u4ef6\u4e3a\u4f8b\uff0c\u770b\u770b\u5728\u793a\u4f8b\u4e2d\u4f7f\u7528render\u51fd\u6570\u65f6\u6548\u679c\u5982\u4f55\u3002\n <\/div>\n
\n index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span> 
   <head><\/span>
      <title><\/span>Vue.js Component<\/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 = \"component_test\">
         <testcomponent><\/testcomponent>
      <\/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
 Vue.component('testcomponent',{ 
   template : '<h1><\/span>Hello Students!<\/h1><\/span>'
});
var vm = new Vue({
   el: '#component_test'
})
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u7b80\u5355\u7684CSS\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 \u6e32\u67d3\u529f\u80fd_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c1\u5f20 <\/p>\n

\n \u5728\u8fd9\u91cc\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u8be5\u7ec4\u4ef6\u5c06\u4e0a\u8ff0\u7ed3\u679c\u663e\u793a\u4e3aHello Students\u3002\u73b0\u5728\uff0c\u5982\u679c\u60a8\u91cd\u590d\u4f7f\u7528\u8be5\u7ec4\u4ef6\uff0c\u60a8\u5c06\u770b\u5230\u7ed3\u679c\u5c06\u88ab\u4e00\u6b21\u53c8\u4e00\u6b21\u5730\u6253\u5370\u3002\u4f8b\u5982\uff0c\n <\/div>\n
\n
 <div id = \"component_test\">
   <testcomponent><\/testcomponent>
   <testcomponent><\/testcomponent>
   <testcomponent><\/testcomponent>
   <testcomponent><\/testcomponent>
   <testcomponent><\/testcomponent>
<\/div><\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8f93\u51fa: <\/strong>\n <\/div>\n

Vue.js \u6e32\u67d3\u529f\u80fd_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c2\u5f20 <\/p>\n

\n \u5047\u8bbe\u60a8\u4e0d\u5e0c\u671b\u4e00\u6b21\u53c8\u4e00\u6b21\u5730\u6253\u5370\u76f8\u540c\u7684\u6587\u672c\uff0c\u90a3\u4e48\u60a8\u4f1a\u600e\u4e48\u505a\uff1f\u8ba9\u6211\u4eec\u8fdb\u884c\u4e00\u4e9b\u66f4\u6539\uff0c\u7136\u540e\u5728\u7ec4\u4ef6\u5185\u952e\u5165\u4ee5\u4e0b\u5185\u5bb9:\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span> 
   <head><\/span>
      <title><\/span>Vue.js Component<\/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 = \"component_test\">
   <testcomponent>Hello Rahul!<\/testcomponent>
   <testcomponent>Hello James!<\/testcomponent>
   <testcomponent>Hello Alex!<\/testcomponent>
   <testcomponent>Hello Priti!<\/testcomponent>
   <testcomponent>Hello Mohan!<\/testcomponent>
      <\/div><\/span>
      <script src=\"index.js\"><\/script><\/span>
   <\/body><\/span>
<\/html><\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n Index.js\u6587\u4ef6\u4e0e\u4e0a\u9762\u7684\u6587\u4ef6\u76f8\u540c\u3002\n <\/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 \u6e32\u67d3\u529f\u80fd_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c3\u5f20 <\/p>\n

\n \u60a8\u53ef\u4ee5\u770b\u5230\u8f93\u51fa\u4e0e\u8f83\u65e9\u3002\n <\/div>\n

\u4f7f\u7528\u63d2\u69fd<\/h3>\n
\n \u73b0\u5728\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u7ec4\u4ef6\u63d0\u4f9b\u7684\u63d2\u69fd\u6765\u83b7\u5f97\u6240\u9700\u7684\u7ed3\u679c\u3002\n <\/div>\n
\n \u8bed\u6cd5: <\/strong>\n <\/div>\n
\n
 template : '<h1><\/span><slot><\/slot><\/h1><\/span>',
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8bf7\u53c2\u89c1\u4ee5\u4e0b\u793a\u4f8b:\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span> 
   <head><\/span>
      <title><\/span>Vue.js Component<\/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 = \"component_test\">
   <testcomponent>Hello Rahul!<\/testcomponent>
   <testcomponent>Hello James!<\/testcomponent>
   <testcomponent>Hello Alex!<\/testcomponent>
   <testcomponent>Hello Priti!<\/testcomponent>
   <testcomponent>Hello Mohan!<\/testcomponent>
      <\/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
 Vue.component('testcomponent',{ 
    template : '<h1><\/span><slot><\/slot><\/h1><\/span>',
});
var vm = new Vue({
   el: '#component_test'
})
<\/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 \u6e32\u67d3\u529f\u80fd_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c4\u5f20 <\/p>\n

\u5982\u4f55\u4f7f\u7528\u6e32\u67d3\u51fd\u6570\uff1f<\/h3>\n
\n \u5047\u8bbe\u60a8\u5fc5\u987b\u66f4\u6539\u989c\u8272\u548c\u4f8b\u5982\uff0c\u8f93\u51fa\u7ed3\u679c\u7684\u5927\u5c0f\uff0c\u6211\u4eec\u5728\u5148\u524d\u7684\u793a\u4f8b\u4e2d\u4f7f\u7528\u4e86h1\u6807\u7b7e\uff0c\u5e76\u4e14\u6211\u4eec\u60f3\u66f4\u6539
\n HTML\u6807\u7b7e\u5230p\u6807\u7b7e\u6216div\u6807\u7b7e\u6216\u540c\u4e00\u7ec4\u4ef6\u7684\u4efb\u4f55\u5176\u4ed6\u6807\u7b7e\u3002\u6211\u4eec\u5177\u6709\u4f7f\u7528render\u51fd\u6570\u8fdb\u884c\u66f4\u6539\u7684\u6240\u6709\u7075\u6d3b\u6027\u3002\u6e32\u67d3\u529f\u80fd\u901a\u8fc7\u4f7f\u5176\u901a\u7528\u5e76\u5e2e\u52a9\u4f7f\u7528\u540c\u4e00\u7ec4\u4ef6\u4f20\u9012\u53c2\u6570\u6765\u5e2e\u52a9\u4f7f\u7ec4\u4ef6\u52a8\u6001\u5316\u5e76\u4f7f\u7528\u6240\u9700\u7684\u65b9\u5f0f\u3002\n <\/div>\n
\n \u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u793a\u4f8b\u6765\u6f14\u793a\u6e32\u67d3\u529f\u80fd\u7684\u4f7f\u7528:\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span> 
   <head><\/span>
      <title><\/span>Vue.js Component<\/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 = \"component_test\">
   <testcomponent :elementtype = \"'div,red,25,div1'\">Hello Rahul!<\/testcomponent>
   <testcomponent :elementtype = \"'h2,brown,25,div1'\">Hello James!<\/testcomponent>
   <testcomponent :elementtype = \"'p,blue,25,ptag'\">Hello Alex!<\/testcomponent>
   <testcomponent :elementtype = \"'div,green,25,divtag'\">Hello Priti!<\/testcomponent>
   <testcomponent :elementtype = \"'h4,blue,25,ptag'\">Hello Mohan!<\/testcomponent>
      <\/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
 Vue.component('testcomponent',{ 
    render :function(createElement){
               var a = this.elementtype.split(\",\");
               return createElement(a[0],{
                  attrs:{
                     id:a[3],
                     style:\"color:\"+a[1]+\";font-size:\"+a[2]+\";\"
                  }
               },
               this.$slots.default
               )
            },
            props:{
               elementtype:{
                  attributes:String,
                  required:true
               }
            }
         });
         var vm = new Vue({
            el: '#component_test'
         })
<\/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 \u6e32\u67d3\u529f\u80fd_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c5\u5f20 <\/p>\n

\u793a\u4f8b\u8bf4\u660e<\/h3>\n
\n \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u6211\u4eec\u5df2\u7ecf\u66f4\u6539\u4e86\u7ec4\u4ef6\uff0c\u5e76\u5728Index.js\u6587\u4ef6\u4e2d\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u6dfb\u52a0\u4e86\u5177\u6709
\n props\u5c5e\u6027<\/strong>\u7684
\n render\u51fd\u6570<\/strong>:\n <\/div>\n
\n
 Vue.component('testcomponent',{ 
    render :function(createElement){
               var a = this.elementtype.split(\",\");
               return createElement(a[0],{
                  attrs:{
                     id:a[3],
                     style:\"color:\"+a[1]+\";font-size:\"+a[2]+\";\"
                  }
               },
               this.$slots.default
               )
            },
            props:{
               elementtype:{
                  attributes:String,
                  required:true
               }
            }
         });
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5728\u8fd9\u91cc\uff0cprops\u5c5e\u6027\u770b\u8d77\u6765\u50cf\u4e0b\u9762\u7684\u4ee3\u7801:\n <\/div>\n
\n
 props:{
               elementtype:{
                  attributes:String,
                  required:true
               }
            }
         });
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5f53\u6211\u4eec\u4f7f\u7528\u5e26\u6709\u6e32\u67d3\u529f\u80fd\u7684\u7ec4\u4ef6\u65f6\uff0c\u5b83\u4eec\u6ca1\u6709\u6a21\u677f\u6807\u7b7e\u6216\u5c5e\u6027\u3002\u4ee3\u66ff\u5b83\u4eec\uff0c\u5b83\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3arender\u7684\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u63a5\u6536\u4ee5\u4e0b\u7ed3\u6784\u7684createElement:\n <\/div>\n
\n \u8bed\u6cd5: <\/strong>\n <\/div>\n
\n
 (renderElement: String | Component, definition: Object, children: String | Array) argument 
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\u53ef\u4ee5\u770b\u5230\u5b83:\n <\/div>\n
\n
 render :function(createElement){
               var a = this.elementtype.split(\",\");
               return createElement(a[0],{
                  attrs:{
                     id:a[3],
                     style:\"color:\"+a[1]+\";font-size:\"+a[2]+\";\"
                  }
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6211\u4eec\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a
\n elementtype <\/strong>\u7684\u5c5e\u6027\uff0c\u8be5\u5c5e\u6027\u91c7\u7528\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u5c5e\u6027\u5b57\u6bb5\u3002\u5728\u53e6\u4e00\u4e2a\u5fc5\u586b\u5b57\u6bb5\u4e2d\uff0c\u6211\u4eec\u63d0\u5230\u4e86\u8be5\u5b57\u6bb5\u662f\u5fc5\u586b\u5b57\u6bb5\u3002\n <\/div>\n
\n \u8bf7\u53c2\u9605\u6e32\u67d3\u51fd\u6570\u4ee3\u7801\uff0c\u5176\u4e2d\u6211\u4eec\u5df2\u4f7f\u7528elementtype\u5c5e\u6027\uff0c\u5982\u4e0b\u6240\u793a:\n <\/div>\n
\n
 render :function(createElement){
               var a = this.elementtype.split(\",\");
               return createElement(a[0],{
                  attrs:{
                     id:a[3],
                     style:\"color:\"+a[1]+\";font-size:\"+a[2]+\";\"
                  }
               },
               this.$slots.default
               )
            },
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n render\u51fd\u6570\u5c06createElement\u4f5c\u4e3a\u53c2\u6570\u5e76\u8fd4\u56de\u76f8\u540c\u7684\u503c\u3002 CreateElement\u7684\u521b\u5efa\u65b9\u5f0f\u4e0e
\n JavaScript \u76f8\u540c\u3002\u6211\u4eec\u8fd8\u4f7f\u7528attrs\u5b57\u6bb5\u4e2d\u7684\u503c\u5728\u9017\u53f7\u4e0a\u62c6\u5206\u4e86\u5143\u7d20\u7c7b\u578b\u3002\n <\/div>\n
\n CreateElement\u5c06\u7b2c\u4e00\u4e2a\u53c2\u6570\u4f5c\u4e3a\u8981\u521b\u5efa\u7684elementtag\u3002\u5b83\u88ab\u4f20\u9012\u7ed9\u7ec4\u4ef6\uff0c\u5982\u4e0b\u6240\u793a:\n <\/div>\n
\n
 <testcomponent :elementtype = \"'div,red,25,div1'\">Hello Rahul!<\/testcomponent> 
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8be5\u7ec4\u4ef6\u63a5\u53d7props\u5b57\u6bb5\u4f5c\u4e3a\u4e0a\u8ff0\u4ee3\u7801\u3002\u5b83\u4ee5\u7b26\u53f7: \u5f00\u5934\uff0c\u7136\u540e\u6307\u5b9a\u9053\u5177\u540d\u79f0\u3002\u6307\u5b9a\u9053\u5177\u540d\u79f0\u540e\uff0c\u6211\u4eec\u5fc5\u987b\u4f20\u9012\u5143\u7d20\u6807\u7b7e\uff0c\u989c\u8272\uff0c\u5b57\u4f53\u5927\u5c0f\u548c\u5143\u7d20\u7684ID\u3002\n <\/div>\n
\n \u5728render\u51fd\u6570\u4e2d\uff0c\u60a8\u53ef\u4ee5\u770b\u5230\u7b2c\u4e00\u4e2a\u5143\u7d20\u662fcreateElement\u5b57\u6bb5\u4e2d\u7684elementtag\u8d4b\u4e88createElemet\u7684\u65b9\u6cd5\u5982\u4e0b:\n <\/div>\n
\n
 return createElement(a[0],{
                  attrs:{
                     id:a[3],
                     style:\"color:\"+a[1]+\";font-size:\"+a[2]+\";\"
                  }
               },
               this.$slots.default
               )
            },
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c
\n a [0] <\/strong>\u662fhtml\u5143\u7d20\u6807\u8bb0\u3002\u63a5\u4e0b\u6765\u7684\u53c2\u6570\u662felement\u6807\u7b7e\u7684\u5c5e\u6027\u3002\u5b83\u4eec\u5728
\n attr <\/strong>\u5b57\u6bb5\u4e2d\u5b9a\u4e49\u5982\u4e0b:\n <\/div>\n
\n
 attrs:{
                     id:a[3],
                     style:\"color:\"+a[1]+\";font-size:\"+a[2]+\";\"
                  }
               },
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u4e3a\u5143\u7d20\u6807\u7b7e\u5b9a\u4e49\u4e86\u4e24\u4e2a\u5c5e\u6027: id\u6807\u7b7e\u548cstyle\u6807\u7b7e\u3002\n <\/div>\n

\u5728id\u6807\u8bb0\u4e2d\uff0c\u6211\u4eec\u4f20\u9012\u4e86[3]\uff0c\u8fd9\u662f\u5728\u7528\u9017\u53f7\u5206\u5272\u540e\u7684\u503c\u3002<\/span>
\n \u5728\u6837\u5f0f\u6807\u7b7e\u4e2d\uff0c\u6211\u4eec\u5206\u522b\u4f20\u9012\u4e86a [1]\u548ca [2]\u6765\u5b9a\u4e49\u989c\u8272\u548c\u5b57\u4f53\u5927\u5c0f\u3002<\/span> <\/p>\n

\n \u6211\u4eec\u5728\u7ec4\u4ef6\u4e2d\u7ed9\u51fa\u7684\u6d88\u606f\u6307\u5b9a\u5982\u4e0b:\n <\/div>\n
\n
 <testcomponent :elementtype = \"'div,red,25,div1'\">Hello Rahul!<\/testcomponent>
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u63d2\u69fd\u5b57\u6bb5\u7528\u4e8e\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5b9a\u4e49\u6211\u4eec\u8981\u5728createElement\u4e2d\u6253\u5370\u7684\u6587\u672c:\n <\/div>\n
\n
 this.$slots.default
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5728\u7a0b\u5e8f\u6267\u884c\u540e\uff0c\u770b\u5230\u8f93\u51fa\uff0c\u60a8\u5c06\u770b\u5230\uff0c\u6240\u6709\u8f93\u51fa\u6761\u76ee\u5747\u4ee5\u7279\u5b9a\u65b9\u5f0f\u663e\u793a\u3002\u8fd9\u662f\u56e0\u4e3a\u6211\u4eec\u4ee5\u7279\u5b9a\u65b9\u5f0f\u5b9a\u4e49\u4e86\u7ec4\u4ef6\u7ed3\u6784\u4e2d\u7684\u5143\u7d20\u3002\n <\/div>\n
\n
 <div id = \"component_test\"> 
   <testcomponent :elementtype = \"'div,red,25,div1'\">Hello Rahul!<\/testcomponent>
   <testcomponent :elementtype = \"'h2,brown,25,div1'\">Hello James!<\/testcomponent>
   <testcomponent :elementtype = \"'p,blue,25,ptag'\">Hello Alex!<\/testcomponent>
   <testcomponent :elementtype = \"'div,green,25,divtag'\">Hello Priti!<\/testcomponent>
   <testcomponent :elementtype = \"'h4,blue,25,ptag'\">Hello Mohan!<\/testcomponent>
      <\/div><\/span>
<\/span><\/code><\/pre>\n<\/p><\/div>\n

Vue.js\u6e32\u67d3\u51fd\u6570\u4e2d\u7684\u4e8b\u4ef6\u7ed1\u5b9a<\/h3>\n
\n \u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u793a\u4f8b\u6765\u6f14\u793aVue.js\u6e32\u67d3\u51fd\u6570\u4e2d\u7684\u4e8b\u4ef6\u7ed1\u5b9a\u3002\u8bf7\u53c2\u89c1\u4ee5\u4e0b\u793a\u4f8b:\n <\/div>\n
\n \u793a\u4f8b<\/strong>\n <\/div>\n
\n Index.html\u6587\u4ef6: <\/strong>\n <\/div>\n
\n
 <html><\/span> 
   <head><\/span>
      <title><\/span>Vue.js Event binding in render function<\/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=\"render_1\"><\/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
 new Vue({
  el: '#render_1',
  data() {
    return {
      clickCount: 0,
    }
  },
  methods: {
    onClick() {
      this.clickCount += 1;
    }
  },
  render(createElement) {
    const button = createElement('button', {
      on: {
        click: this.onClick
      }
    }, 'Click me');
    const counter = createElement('span', [
      'Number of clicks:',
      this.clickCount
    ]);
    return createElement('div', [
      button, counter
    ])
  }
});
<\/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 \u6e32\u67d3\u529f\u80fd_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c6\u5f20 <\/p>\n

\n \u5f53\u60a8\u5355\u51fb\"\u5355\u51fb\u6211\"\u6309\u94ae\u65f6\uff0c\u60a8\u5c06\u770b\u5230\u5355\u51fb\u6b21\u6570\u5df2\u663e\u793a\u4e3a\u60a8\u7684\u70b9\u51fb\u6b21\u6570\u70b9\u51fb\u4e86\u6309\u94ae\u3002\u53c2\u89c1\u8f93\u51fa:\n <\/div>\n

Vue.js \u6e32\u67d3\u529f\u80fd_https:\/\/bianchenghao6.com_\u3010vue\u6559\u7a0b\u3011_\u7b2c7\u5f20 <\/p>\n

\n \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6309\u94ae\u88ab\u5355\u51fb\u56db\u6b21\u3002\n <\/div>\n
\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"Vue.js \u6e32\u67d3\u529f\u80fdzh-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-987","post","type-post","status-publish","format-standard","hentry","category-vuejc"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/987"}],"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=987"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/987\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=987"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=987"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=987"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}