{"id":52832,"date":"2024-12-03T09:21:45","date_gmt":"2024-12-03T01:21:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52832\/"},"modified":"2024-12-03T09:21:45","modified_gmt":"2024-12-03T01:21:45","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-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52832\/","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><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f <\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300a\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f \u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241123\/17323618116741be5388904.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 Vue \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>\u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528\uff1a<\/p>\n<pre>&lt;input v-focus-right&gt;<\/pre>\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>\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>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f \u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5177\u6709 Webnd AMM \u673a\u5668\u4eba\u7ecf\u9a8c\u7684\u533a\u5757\u94fe\u5f00\u53d1\u4eba\u5458\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f \u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300a\u5982\u4f55\u5728 Vue \u4e2d\u5feb\u901f\u4e3a\u8f93\u5165\u6846\u6dfb\u52a0\u7126\u70b9\u5149\u6807\u5e76\u7f6e\u4e8e\u672b\u5c3e\uff1f \u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002 \u5982\u4f55\u5728 Vue \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; }); }); } }); \u5728\u7ec4\u4ef6\u4e2d\u4f7f\u7528\uff1a &lt;input v-focus-right&gt; \u65b9\u6cd5 2\uff1aVue \u63d2\u4ef6 \u63d2\u4ef6\u662f\u4e00\u79cd\u53ef\u4ee5\u6dfb\u52a0\u5230 [&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-52832","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52832","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=52832"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52832\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}