{"id":27837,"date":"2024-11-24T09:22:35","date_gmt":"2024-11-24T01:22:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27837\/"},"modified":"2024-11-24T09:22:35","modified_gmt":"2024-11-24T01:22:35","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-vue-%e4%b8%ad%e5%bf%ab%e9%80%9f%e4%b8%ba%e8%be%93%e5%85%a5%e6%a1%86%e6%b7%bb%e5%8a%a0%e7%84%a6%e7%82%b9%e5%85%89%e6%a0%87%e5%b9%b6%e7%bd%ae%e4%ba%8e%e6%9c%ab%e5%b0%be","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27837\/","title":{"rendered":"\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173132208580283.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728  \u4e2d\u4fbf\u6377\u5730\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u653e\u7f6e\u5728\u672b\u5c3e\uff1f<\/strong><\/p>\n<p>\u5728 Vue \u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u7ecf\u5e38\u9700\u8981\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\uff0c\u5e76\u5c06\u5176\u653e\u7f6e\u5728\u672b\u5c3e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5feb\u901f\u7b80\u4fbf\u7684\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u65b9\u6cd5 1\uff1aVue \u5168\u5c40\u81ea\u5b9a\u4e49\u6307\u4ee4<\/strong><\/p>\n<p>\u5168\u5c40\u81ea\u5b9a\u4e49\u6307\u4ee4\u662f\u4e00\u79cd\u53ef\u4ee5\u5e94\u7528\u4e8e\u4efb\u4f55 Vue \u7ec4\u4ef6\u7684\u6307\u4ee4\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u521b\u5efa\u4ee5\u4e0b\u81ea\u5b9a\u4e49\u6307\u4ee4\uff1a<\/p>\n<pre>\/\/ main.js\nVue.directive('focus-right', {\n  inserted: function (el) {\n    el.addEventListener('focus', function () {\n      const length = el.value.length;\n      setTimeout(() =&gt; {\n        el.selectionStart = length;\n        el.selectionEnd = length;\n      });\n    });\n  }\n});<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>&lt;input v-focus-right&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1aVue \u63d2\u4ef6<\/strong><\/p>\n<p>\u63d2\u4ef6\u662f\u4e00\u79cd\u53ef\u4ee5\u6dfb\u52a0\u5230 Vue \u5b9e\u4f8b\u7684\u9644\u52a0\u529f\u80fd\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a FocusRightPlugin \u7684\u63d2\u4ef6\uff1a<\/p>\n<pre>\/\/ focusPlugin.js\nconst FocusRightPlugin = {\n  install(Vue) {\n    Vue.prototype.$inputFocusRight = function (e) {\n      const input = e.target;\n      const length = input.value.length;\n      setTimeout(() =&gt; {\n        input.selectionStart = length;\n        input.selectionEnd = length;\n      });\n    };\n  }\n};\n\n\/\/ \u5728 main.js \u91cc\nimport FocusRightPlugin from '.\/focusPlugin';\n\nVue.use(FocusRightPlugin);\n\n\/\/ \u7136\u540e\u5728\u7ec4\u4ef6\u91cc\u7528\n&lt;input @focus=\"$inputFocusRight\"&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e24\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5\u5728 Vue \u9879\u76ee\u4e2d\u8f7b\u677e\u4e14\u4fbf\u6377\u5730\u4e3a\u8f93\u5165\u6846\u65bd\u52a0\u7126\u70b9\u65b9\u6cd5\uff0c\u5e76\u5c06\u5176\u5149\u6807\u653e\u7f6e\u5728\u53f3\u4fa7\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 \u4e2d\u4fbf\u6377\u5730\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u653e\u7f6e\u5728\u672b\u5c3e\uff1f \u5728 Vue \u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u7ecf\u5e38\u9700\u8981\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\uff0c\u5e76\u5c06\u5176\u653e\u7f6e\u5728\u672b\u5c3e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5feb\u901f\u7b80\u4fbf\u7684\u65b9\u6cd5\uff1a \u65b9\u6cd5 1\uff1aVue \u5168\u5c40\u81ea\u5b9a\u4e49\u6307\u4ee4 \u5168\u5c40\u81ea\u5b9a\u4e49\u6307\u4ee4\u662f\u4e00\u79cd\u53ef\u4ee5\u5e94\u7528\u4e8e\u4efb\u4f55 Vue \u7ec4\u4ef6\u7684\u6307\u4ee4\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u521b\u5efa\u4ee5\u4e0b\u81ea\u5b9a\u4e49\u6307\u4ee4\uff1a \/\/ main.js Vue.directive(&#8216;focus-right&#8217;, { inserted: function (el) { el.addEventListener(&#8216;focus&#8217;, function () { const length = el.value.length; setTimeout(() =&gt; { el.selectionStart = length; el.selectionEnd = length; }); }); } }); \u767b\u5f55\u540e\u590d\u5236 \u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b &lt;input v-focus-right&gt; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 2\uff1aVue \u63d2\u4ef6 \u63d2\u4ef6\u662f\u4e00\u79cd\u53ef\u4ee5\u6dfb\u52a0\u5230 Vue \u5b9e\u4f8b\u7684\u9644\u52a0\u529f\u80fd\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a FocusRightPlugin \u7684\u63d2\u4ef6\uff1a \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27837","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27837","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=27837"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27837\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}