{"id":53578,"date":"2024-12-03T17:39:48","date_gmt":"2024-12-03T09:39:48","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53578\/"},"modified":"2024-12-03T17:39:48","modified_gmt":"2024-12-03T09:39:48","slug":"vue%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9e%e7%8e%b0%e6%bb%9a%e5%8a%a8%e5%88%b0%e9%a1%b6%e9%83%a8%e5%8a%a0%e8%bd%bd%e6%9b%b4%e5%a4%9a%e6%95%b0%e6%8d%ae%e4%b8%94%e4%bf%9d%e6%8c%81%e6%bb%9a%e5%8a%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53578\/","title":{"rendered":"Vue\u4e2d\u5982\u4f55\u5b9e\u73b0\u6eda\u52a8\u5230\u9876\u90e8\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u4e14\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Vue\u4e2d\u5982\u4f55\u5b9e\u73b0\u6eda\u52a8\u5230\u9876\u90e8\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u4e14\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8\uff1f<\/h1>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aVue\u4e2d\u5982\u4f55\u5b9e\u73b0\u6eda\u52a8\u5230\u9876\u90e8\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u4e14\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8\uff1f\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241202\/1733112751674d33af42780.jpg\" class=\"aligncenter\" title=\"Vue\u4e2d\u5982\u4f55\u5b9e\u73b0\u6eda\u52a8\u5230\u9876\u90e8\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u4e14\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8\uff1f\u63d2\u56fe\" alt=\"Vue\u4e2d\u5982\u4f55\u5b9e\u73b0\u6eda\u52a8\u5230\u9876\u90e8\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u4e14\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>vue \u6eda\u52a8\u5230\u9876\u90e8\u65f6\u52a0\u8f7d\u66f4\u591a\u6570\u636e\uff0c\u4f46\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8<\/strong><\/p>\n<p>\u5728\u67d0\u4e9b\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u7c7b\u4f3c\u5fae\u4fe1\u804a\u5929\u8bb0\u5f55\u90a3\u6837\uff0c\u5f53\u7528\u6237\u5411\u4e0a\u6eda\u52a8\u5230\u9876\u90e8\u65f6\u52a0\u8f7d\u66f4\u591a\u5386\u53f2\u8bb0\u5f55\uff0c\u4f46\u6eda\u52a8\u6761\u4f4d\u7f6e\u4f9d\u7136\u4fdd\u6301\u5728\u5f53\u524d\u4f4d\u7f6e\u3002<\/p>\n<p>\u4e0b\u9762\u63d0\u4f9b\u4e00\u79cd\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n<pre>&lt;div class=\"container\" @scroll=\"handlescroll\" ref=\"chatlistref\"&gt;\n  &lt;ul&gt;\n    &lt;li v-for=\"item in msgs\"&gt;{{ item }}&lt;\/li&gt;\n  &lt;\/ul&gt;\n&lt;\/div&gt;<\/pre>\n<pre>import { createApp, ref, nextTick } from 'vue'\n\ncreateApp({\n  setup() {\n    const msgs = ref([])\n    const chatListRef = ref()\n\n    const scrollToBottom = async () =&gt; {\n      const chatListElement = chatListRef.value\n      if (chatListElement) {\n        chatListElement.scrollTop = chatListElement.scrollHeight\n      }\n    }\n\n    const handleScroll = (ev) =&gt; {\n      const target = event.target\n      if (target.scrollTop === 0) {\n        \/\/ TODO: \u52a0\u8f7d\u66f4\u591a\u6570\u636e\n        alert('\u6dfb\u52a0\u5b8c\u6570\u636e\u540e\u5e0c\u671b\u505c\u7559\u5728\u5f53\u524d\u6570\u636e\u7684\u4f4d\u7f6e\uff0c\u800c\u4e0d\u662f\u6700\u9876\u90e8')\n      }\n    }\n\n    nextTick(() =&gt; {\n      scrollToBottom()\n    })\n\n    return {\n      msgs,\n      chatListRef,\n      handleScroll\n    }\n  }\n}).mount('#app')<\/pre>\n<p>\u5f53\u5411\u4e0a\u6eda\u52a8\u5230\u9876\u90e8\u65f6\uff0chandlescroll \u51fd\u6570\u4f1a\u88ab\u89e6\u53d1\uff0c\u6b64\u65f6\u53ef\u4ee5\u5224\u65ad scrolltop \u662f\u5426\u4e3a 0\uff0c\u5982\u679c\u662f\uff0c\u5219\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u5e76\u66f4\u65b0 msgs \u6570\u7ec4\u3002\u5173\u952e\u5728\u4e8e\uff0c\u5728\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u540e\uff0c\u9700\u8981\u8c03\u7528 scrolltobottom \u51fd\u6570\u5c06\u6eda\u52a8\u6761\u4f4d\u7f6e\u8c03\u6574\u56de\u5f53\u524d\u4f4d\u7f6e\u3002<\/p>\n<p>\u8bf7\u6ce8\u610f\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u4fee\u6539 scrolltobottom \u51fd\u6570\u4e2d\u7684\u6eda\u52a8\u884c\u4e3a\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8e\u6587\u7ae0\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5982\u4f55\u4f7f\u7528 Python \u5bf9\u9f50\u6587\u672c\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u5217\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Vue\u4e2d\u5982\u4f55\u5b9e\u73b0\u6eda\u52a8\u5230\u9876\u90e8\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u4e14\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8\uff1f \u5b66\u4e60\u6587\u7ae0\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0\u300aVue\u4e2d\u5982\u4f55\u5b9e\u73b0\u6eda\u52a8\u5230\u9876\u90e8\u52a0\u8f7d\u66f4\u591a\u6570\u636e\u4e14\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8\uff1f\u300b\u5c06\u4f1a\u4ecb\u7ecd\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60\u6587\u7ae0\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01 vue \u6eda\u52a8\u5230\u9876\u90e8\u65f6\u52a0\u8f7d\u66f4\u591a\u6570\u636e\uff0c\u4f46\u4fdd\u6301\u6eda\u52a8\u4f4d\u7f6e\u4e0d\u53d8 \u5728\u67d0\u4e9b\u573a\u666f\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u7c7b\u4f3c\u5fae\u4fe1\u804a\u5929\u8bb0\u5f55\u90a3\u6837\uff0c\u5f53\u7528\u6237\u5411\u4e0a\u6eda\u52a8\u5230\u9876\u90e8\u65f6\u52a0\u8f7d\u66f4\u591a\u5386\u53f2\u8bb0\u5f55\uff0c\u4f46\u6eda\u52a8\u6761\u4f4d\u7f6e\u4f9d\u7136\u4fdd\u6301\u5728\u5f53\u524d\u4f4d\u7f6e\u3002 \u4e0b\u9762\u63d0\u4f9b\u4e00\u79cd\u89e3\u51b3\u65b9\u6cd5\uff1a &lt;div class=&#8221;container&#8221; @scroll=&#8221;handlescroll&#8221; ref=&#8221;chatlistref&#8221;&gt; &lt;ul&gt; &lt;li v-for=&#8221;item in msgs&#8221;&gt;{{ item }}&lt;\/li&gt; &lt;\/ul&gt; &lt;\/div&gt; import { createApp, ref, nextTick } from &#8216;vue&#8217; createApp({ setup() { const msgs = ref([]) const chatListRef = ref() const scrollToBottom = async () =&gt; { const chatListElement = chatListRef.value if (chatListElement) { chatListElement.scrollTop = chatListElement.scrollHeight [&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-53578","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53578","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=53578"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53578\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}