{"id":1003,"date":"2022-07-02T19:53:00","date_gmt":"2022-07-02T11:53:00","guid":{"rendered":"http:\/\/blog.xrhoujie.com\/?p=1003"},"modified":"2022-06-21T11:01:03","modified_gmt":"2022-06-21T03:01:03","slug":"web%e4%b8%80%e4%ba%9b%e5%b8%b8%e7%94%a8%e5%87%bd%e6%95%b0%e4%b8%8e%e7%ac%94%e8%ae%b0","status":"publish","type":"post","link":"http:\/\/blog.xrhoujie.com\/?p=1003","title":{"rendered":"web\u4e00\u4e9b\u5e38\u7528\u51fd\u6570\u4e0e\u7b14\u8bb0"},"content":{"rendered":"\n<p>\u3002\u3002\u3002\u771f\u5b9e\u505a\u9879\u76ee\u4e2d\u4f1a\u9047\u5230\u4e00\u4e9b\u9700\u6c42\uff0c\u9700\u8981\u4e00\u5b9a\u7684\u7b97\u6cd5\u6216\u8005\u67d0\u4e9b\u51fd\u6570\u6765\u89e3\u51b3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>1.\u6c42\u6570\u7ec4\u4ea4\u96c6<\/strong>\nlet arr1 =&#91;0,2,4,5,7]\nlet arr2 = &#91;0,3,5,6,8,4,9,55]\nvar newarr = arr1 .filter((v) => arr2 .includes(v))\n\/\/\u4e5f\u53ef\u4ee5\u7528,\u4e0d\u8003\u8651(\u6570\u7ec4\u4e2d\u4e0d\u542bNaN)\nnewarr = arr1.filter((v)=> arr2.indexOf(v)>-1 )\n\/\/filter\u65b9\u6cd5\u662f\u8fd4\u56de\u4e00\u4e2a\u7b26\u5408\u8fc7\u6ee4\u6761\u4ef6\u7684\u65b0\u6570\u7ec4\uff0c\u4e0d\u6539\u53d8\u539f\u6709\u7684\u6570\u7ec4\n\n\n<strong>2.\u6c42\u6570\u7ec4\u5e76\u96c6<\/strong>\narr1.concat(arr2.filter(function(v) {\nreturn arr1.indexOf(v) === -1})) \/\/ &#91;1,2,3,4,5]\n\n<strong>\n3.\u6c42\u591a\u7ef4\u6570\u7ec4\u5408\u5e76\u4e00\u7ef4<\/strong>\nvar arr1 = &#91;&#91;0, 1], &#91;2, 3], &#91;4, 5]];\nvar arr2 = arr1.reduce(function (a, b) { return a.concat(b)} );\n\/\/ arr2 &#91;0, 1, 2, 3, 4, 5]\n\n\n<strong>4.\u6c42\u5b57\u7b26\u4e32\u6570\u7ec4\u8f6c\u6574\u578b<\/strong>\nvar arr2 = &#91;\"0\", \"1\", \"2\", \"3\", \"4\", \"5\"];\nvar arr3 = arr2.map(Number);\nconsole.log(arr3);\/\/\u8f93\u51fa\u4e3a\uff1a&#91;0, 1, 2, 3, 4, 5]\n\n\n<strong>5.\u6570\u7ec4\u53bb\u91cd<\/strong>\nArray.from\u65b9\u6cd5\u7528\u4e8e\u5c06\u4e24\u7c7b\u5bf9\u8c61\u8f6c\u4e3a\u771f\u6b63\u7684\u6570\u7ec4\uff1b\nSet\u7c7b\u4f3c\u4e8e\u6570\u7ec4\uff0c\u4f46\u662f\u672c\u8eab\u6ca1\u6709\u91cd\u590d\u503c\n&#91;...]\u6269\u5c55\u8fd0\u7b97\u7b26 \u7528\u4e8e\u5c55\u5f00\u6570\u7ec4\n1.Array.from(new Set(arr))\n2.&#91;...new Set(arr)]\n3.indexOf(i) \u5c0f\u4e8e0 \u8bf4\u660e\u4e0d\u5b58\u5728\u91cd\u590d\n\n<strong>6.\u4e8c\u5206\u67e5\u627e\u6cd5\n<\/strong>\n\/\/ \u7ed9\u5b9a\u4e00\u4e2a\u6709\u5e8f\uff08\u975e\u964d\u5e8f\uff09\u6570\u7ec4\uff0c\u53ef\u80fd\u542b\u6709\u91cd\u590d\u5143\u7d20\uff0c\u6c42\u6700\u5c0f\u7684i\u4f7f\u5f97A&#91;i]\u7b49\u4e8etarget\uff0c\u4e0d\u5b58\u5728\u5219\u8fd4\u56de-1\r\n        \/\/ target = 7 ,return 5\r\n        \/\/ target = 8, return -1\r\n        function binary_search (arr , item){\r\n            let low = 0\r\n            height = arr.length - 1\r\n            while(low &lt; height){\r\n                let mid = parseInt((height + low) \/ 2)\r\n                let guess = arr&#91;mid]\r\n                if(guess == item){\r\n                    return mid\r\n                }else if(guess > item){\r\n                    height = mid - 1\r\n                }else{\r\n                    low = mid + 1\r\n                }\r\n            }\r\n            return -1\r\n        }\r\n        let myArr = &#91;1,2,3,5,6,7,7,10]\r\n        console.log(binary_search(myArr,7));   \/\/ \u6700\u540e\u8f93\u51fa\u7684\u662f7\u5bf9\u5e94\u7684\u7d22\u5f15\u4e0b\u6807 5\r\n        console.log(binary_search(myArr,8));   \/\/ \u627e\u4e0d\u52308 \u8f93\u51fa\u7684\u662f -1\n\n<\/code><\/pre>\n\n\n\n<p><strong>vue.js&#8211;\u52a8\u6001\u66f4\u6539css<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u68c0\u6d4b\u8868\u5355\u662f\u5426\u8f93\u5165\uff0c\u5982\u679c\u6709\u8f93\u5165 \u8fdb\u5165watch\uff0cnewVal\u83b7\u53d6\u6700\u65b0\u503c\uff0cbtnActive = true\uff0c\u5219butsubFocus \u5c5e\u6027\u9009\u62e9\u5668css\u751f\u6548\uff0c\u5426\u5219\u4f7f\u7528\u9ed8\u8ba4\u7684butsub;\n&lt;input type=\"button\" value='\u7acb\u5373\u6ce8\u518c' class='butsub' @click=\"submit()\" :class=\"{ 'butsubFocus': btnActive }\"&gt;\n\ndata() {\n    return {\n      btnActive: false,\n    }\n  },\n\nwatch: {\n    mobile(newVal, oldVal) {\n      \/\/ watch\u53ef\u4ee5\u76d1\u542c\u4e00\u4e9b\u72b6\u6001\u53d1\u751f\u66f4\u6539\u7684\u65f6\u5019\uff0c\u505a\u4e00\u4e9b\u5904\u7406\uff0c\u4fee\u6539\u72b6\u6001\uff0c\u6216\u8005\u5f02\u6b65\u64cd\u4f5c\n      newVal != '' ? this.btnActive = true : this.btnActive = false;\n    }\n  },\n\n\n .butsub {\n      background: #E4E5E6;\n      color: #959697;\n    }\n\n\n .butsubFocus {\n      background: #7094F0;\n      color: #FFFFFF\n    }\n<\/code><\/pre>\n\n\n\n<p><strong>vue.js&#8211;css\u64cd\u4f5cxx\u65f6\u95f4\u5185\u4e0d\u5141\u8bb8\u70b9\u51fb<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n\n&lt;div class=\"audioWrap\" @click=\"musicPlay()\" ref=\"audioRef\" v-if=\"show\"&gt;\n            &lt;p class=\"audioText\"&gt;{{audioNumber}}' \n              &lt;span class=\"voiceBox\"&gt;\n                &lt;img src=\"@\/images\/report\/voice2.png\" alt=\"\" class=\"voiceImg\" ref=\"iconRef\"&gt;\n              &lt;\/span&gt;\n            &lt;\/p&gt;\n        &lt;\/div&gt;\n\naudioNumber:'14',\naudioState:false,\n musicPlay(){\n      let time = this.audioNumber * 1000\n      if(this.audioState == false){\n        this.audioState = true;\n        this.musicStatus.play();\n        this.$refs.audioRef.style.pointerEvents='none'\n      }\n      if(this.audioState == true){\n        setTimeout(()=&gt;{\n          this.audioState = false\n          this.$refs.audioRef.style.pointerEvents='auto'\n        },time)\n      }\n    },\n<\/code><\/pre>\n\n\n\n<p><strong>vue.js&#8211;\u8bed\u97f3\u804a\u5929\u5587\u53ed\u52a8\u6001\u6362\u56fe<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\n changeIconPic(){\n      var imgArr = &#91;\"https:\/\/file.coralwin.cn\/2205241635527682983.png\",\"https:\/\/file.coralwin.cn\/2205241636102714284.png\",\"https:\/\/file.coralwin.cn\/2205241636226383410.png\"];\n      \/\/\u521b\u5efa\u4e00\u4e2a\u53d8\u91cf\uff0c\u7528\u6765\u4fdd\u5b58\u5f53\u524d\u56fe\u7247\u7684\u7d22\u5f15\n      var index = 0;\n      \/\/\u5b9a\u4e49\u4e00\u4e2a\u53d8\u91cf\uff0c\u7528\u6765\u4fdd\u5b58\u5b9a\u65f6\u5668\u7684\u6807\u8bc6\n      var timer;\n      \/\/\u5728\u5f00\u542f\u5b9a\u65f6\u5668\u4e4b\u524d\uff0c\u9700\u8981\u5c06\u5f53\u524d\u5143\u7d20\u4e0a\u7684\u5176\u4ed6\u5b9a\u65f6\u5668\u5173\u95ed\n      clearInterval(timer);\n      \/*\n           * \u5f00\u542f\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u6765\u81ea\u52a8\u5207\u6362\u56fe\u7247\n           *\/\n          timer = setInterval(()=&gt;{\n            \/\/\u4f7f\u7d22\u5f15\u81ea\u589e\n            index++;\n            \/\/\u5224\u65ad\u7d22\u5f15\u662f\u5426\u8d85\u8fc7\u6700\u5927\u7d22\u5f15\n            if(index &gt; imgArr.length){\n              \/\/\u5219\u5c06index\u8bbe\u7f6e\u4e3a0\n              index = 3;\n              clearInterval(timer);\n            }\n            this.$refs.iconRef.src= imgArr&#91;index - 1]\n          },1000);\n    },\n<\/code><\/pre>\n\n\n\n<p><strong>audio\u64cd\u4f5c\u76f8\u5173<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u653e\u5230mounted\u91cc\u9762\nthis.audio = new Audio()\n      this.audio.src = this.src\n      this.audio.addEventListener('canplaythrough', () =&gt; {\n        this.duration = this.format(this.audio.duration)\n      })\n      this.audio.onplay = () =&gt; {\n        this.animate = true\n        this.timer = setInterval(() =&gt; {\n          this.animate = false\n          setTimeout(() =&gt; {\n            this.animate = true\n          }, 50)\n        }, 1250);\n      }\n      this.audio.onpause = () =&gt; {\n        this.animate = false\n        this.timer &amp;&amp; clearInterval(this.timer)\n      }\n      this.audio.onended = () =&gt; {\n        this.animate = false\n        this.timer &amp;&amp; clearInterval(this.timer)\n      }\n      window.audioList.push(this.audio) \/\/\u6240\u6709\u5b9e\u4f8b\u52a0\u5165\u5168\u5c40\u53d8\u91cf\n      console.log(window.audioList)\n    },\n    methods: {\n      play() {\n        if (this.audio.paused) {\n          this.audio.play()\n        } else {\n          window.audioList.forEach(audio =&gt; { \/\/\u5f00\u59cb\u524d\u5148\u5173\u95ed\u6240\u6709\u53ef\u80fd\u6b63\u5728\u8fd0\u884c\u7684\u5b9e\u4f8b\n            audio.pause()\n          })\n        }\n      },\n      format(s) {\n        var t = '';\n        if (s &gt; -1) {\n          var min = Math.floor(s \/ 60) % 60;\n          var sec = s % 60;\n\n          if (min &lt; 10) {\n            t += \"0\";\n          }\n          t += min + \"'\";\n          if (sec &lt; 10) {\n            t += \"0\";\n          }\n          t += sec.toFixed(2);\n        }\n        \/\/ eslint-disable-next-line no-useless-escape\n        t = t.replace('.', '\\\"')\n        return t;\n      },\n<\/code><\/pre>\n\n\n\n<p><strong>\u5b50\u76d2\u5b50\u6491\u5f00\u7236\u76d2\u5b50css<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u539f\u5219\uff1a\n1.\u7236\u76d2\u5b50\u4e0d\u8981\u8bbe\u7f6e\u9ad8\u5ea6\uff0c\u9ed8\u8ba4\u9ad8\u5ea6height:auto;\n2.\u5b50\u76d2\u5b50\u8981\u6709\u660e\u786e\u7684\u5bbd\u9ad8\uff0c\u4e14\u5b50\u76d2\u5b50\u662f \u5757\u7ea7\u5143\u7d20(\u65e2 float: left;)\n3.\u6700\u540e\u8981\u5728\u7236\u76d2\u5b50\u4e0b\uff0c(\u5b50\u76d2\u5b50\u7684\u5144\u5f1f\u8282\u70b9\uff0c\u6dfb\u52a0\u6807\u7b7e)\n&lt;div class=\"clearfloat\"&gt;&lt;\/div&gt;\n  .clearfloat{\n    clear:both;\n    height:0;\n  }\n<\/code><\/pre>\n\n\n\n<p><strong>css padding\u4e0emargin<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>eg:\npadding: 20px;\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u540420px\u3002\uff09\npadding: 20px 40px;\uff08\u4e0a\u3001\u4e0b20px\uff1b\u5de6\u3001\u53f340px\u3002\uff09\npadding: 20px 40px 60px;\uff08\u4e0a20px\uff1b\u5de6\u3001\u53f340px\uff1b\u4e0b60px\u3002\uff09\npadding: 20px 40px 60px 80px;\uff08\u4e0a20px\uff1b\u53f340px\uff1b\u4e0b60px\uff1b\u5de680px\u3002\uff09\n\u5728css\u4e2d\u4f7f\u7528padding\u53ef\u4ee5\u5c06padding-top\uff0cpadding-right\uff0cpadding-bottom\uff0cpadding-left\uff0c\u7f29\u5199\u4e3a\u4e00\u4e2a\u6807\u8bb0\uff0c\u987a\u5e8f\u4e3a\u4e0a\u53f3\u4e0b\u5de6\uff08\u987a\u65f6\u9488\uff09\u3002\n\nmargin: 20px;\uff08\u4e0a\u3001\u4e0b\u3001\u5de6\u3001\u53f3\u540420px\u3002\uff09\nmargin: 20px 40px;\uff08\u4e0a\u3001\u4e0b20px\uff1b\u5de6\u3001\u53f340px\u3002\uff09\nmargin: 20px 40px 60px;\uff08\u4e0a20px\uff1b\u5de6\u3001\u53f340px\uff1b\u4e0b60px\u3002\uff09\nmargin: 20px 40px 60px 80px;\uff08\u4e0a20px\uff1b\u53f340px\uff1b\u4e0b60px\uff1b\u5de680px\u3002\uff09\n\u5728css\u4e2d\u4f7f\u7528margin\u53ef\u4ee5\u5c06margin-top\uff0cmargin-right\uff0cmargin-bottom\uff0cmargin-left\uff0c\u7f29\u5199\u4e3a\u4e00\u4e2a\u6807\u8bb0\uff0c\u987a\u5e8f\u4e3a\u4e0a\u53f3\u4e0b\u5de6\uff08\u987a\u65f6\u9488\uff09\u3002\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u3002\u3002\u3002\u771f\u5b9e\u505a\u9879\u76ee\u4e2d\u4f1a\u9047\u5230\u4e00\u4e9b\u9700\u6c42\uff0c\u9700\u8981\u4e00\u5b9a\u7684\u7b97\u6cd5\u6216\u8005\u67d0\u4e9b\u51fd\u6570\u6765\u89e3\u51b3 vue.js&#8211;\u52a8\u6001\u66f4\u6539css  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[19],"_links":{"self":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/1003"}],"collection":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1003"}],"version-history":[{"count":3,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/1003\/revisions"}],"predecessor-version":[{"id":1025,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=\/wp\/v2\/posts\/1003\/revisions\/1025"}],"wp:attachment":[{"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1003"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1003"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.xrhoujie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1003"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}