{"id":5963,"date":"2024-04-17T23:07:14","date_gmt":"2024-04-17T15:07:14","guid":{"rendered":"http:\/\/zyg.luchers.cn\/?p=5963"},"modified":"2024-04-17T23:11:32","modified_gmt":"2024-04-17T15:11:32","slug":"%e7%ac%ac%e4%b8%89%e7%ab%a0%e3%80%81%e4%bd%bf%e7%94%a8%e8%84%9a%e6%89%8b%e6%9e%b6%ef%bc%88%e8%a7%a3%e5%86%b3ajax%e8%b7%a8%e5%9f%9f%e9%97%ae%e9%a2%98%e3%80%81vue-resource%e3%80%81slot%e6%8f%92%e6%a7%bd","status":"publish","type":"post","link":"http:\/\/zyg.luchers.cn\/index.php\/2024\/04\/17\/%e7%ac%ac%e4%b8%89%e7%ab%a0%e3%80%81%e4%bd%bf%e7%94%a8%e8%84%9a%e6%89%8b%e6%9e%b6%ef%bc%88%e8%a7%a3%e5%86%b3ajax%e8%b7%a8%e5%9f%9f%e9%97%ae%e9%a2%98%e3%80%81vue-resource%e3%80%81slot%e6%8f%92%e6%a7%bd\/","title":{"rendered":"\u7b2c\u4e09\u7ae0\u3001\u4f7f\u7528\u811a\u624b\u67b6\uff08\u521d\u59cb\u5316\u811a\u624b\u67b6\u3001ref\u5c5e\u6027\u3001\u63d2\u4ef6\u3001webStorage\u3001\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u3001\u5168\u5c40\u4e8b\u4ef6\u603b\u7ebf\u3001vue\u5c01\u88c5\u548c\u8fc7\u5ea6\u52a8\u753b\uff09"},"content":{"rendered":"<h1>\u7b2c\u4e09\u7ae0\u3001\u4f7f\u7528\u811a\u624b\u67b6<\/h1>\n<h2>1\u3001\u521d\u59cb\u5316\u811a\u624b\u67b6<\/h2>\n<h3>1\u3001\u5177\u4f53\u6b65\u9aa4<\/h3>\n<h4>1\u3001\u7b2c\u4e00\u6b65<\/h4>\n<p>1\u3001\u53ea\u6267\u884c\u4e00\u6b21\uff0c\u5c31\u662f\u8bbe\u7f6e\u5168\u5c40\u5b89\u88c5<\/p>\n<pre><code>@vue\/cli<\/code><\/pre>\n<h4>2\u3001\u7b2c\u4e8c\u6b65<\/h4>\n<p>1\u3001<strong>\u5207\u6362\u5230\u9700\u8981\u521b\u5efa\u9879\u76ee\u7684\u76ee\u5f55<\/strong>\uff0c\u7136\u540e\u4f7f\u7528\u521b\u5efa\u547d\u4ee4<\/p>\n<pre><code>vue create xxxx<\/code><\/pre>\n<h4>3\u3001\u7b2c\u4e09\u6b65<\/h4>\n<p>1\u3001\u542f\u52a8\u9879\u76ee<\/p>\n<pre><code>npm run serve<\/code><\/pre>\n<h4>4\u3001\u6ce8\u610f<\/h4>\n<p>1\u3001\u5982\u679c\u4e0b\u8f7d\u6162\uff0c\u5c31\u4f7f\u7528\u6dd8\u5b9d\u7684\u955c\u50cf<\/p>\n<pre><code>npm config set registry https:\/\/registry.npm.taobao.org<\/code><\/pre>\n<h2>2\u3001\u811a\u624b\u67b6\u7684\u7ed3\u6784<\/h2>\n<h3>1\u3001\u7ed3\u6784<\/h3>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/image-20231112153739504.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/image-20231112153739504.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20231112153739504\" \/><\/div><\/p>\n<h3>2\u3001Render\u51fd\u6570<\/h3>\n<p>1\u3001\u662f\u7528\u6765\u5e2eapp\u7ec4\u4ef6\u521b\u5efa\u5bb9\u5668\u7684\u4e00\u4e2a\u65b9\u6cd5<\/p>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/image-20231112153830824.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/image-20231112153830824.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20231112153830824\" \/><\/div><\/p>\n<p>2\u3001\u4e00\u822c\u53ea\u6709\u5728\u8fd9\u624d\u7528<\/p>\n<h3>3\u3001\u4e0d\u540c\u7248\u672c\u7684Vue<\/h3>\n<h4>1\u3001vue.js\u548cvue.runtime.xxx.js\u7684\u533a\u522b<\/h4>\n<p>1\u3001vue.js\u662f\u5b8c\u6574\u7684vue\u3002\u5305\u542b\u6838\u5fc3\u529f\u80fd\u548c\u6a21\u677f\u89e3\u6790\u5668<\/p>\n<p>2\u3001vue.runtime.xxx.js\u662f\u8fd0\u884c\u7248\u7684vue\uff0c\u53ea\u5305\u542b\uff1a\u6838\u5fc3\u529f\u80fd\u3001\u6ca1\u6709\u6a21\u677f\u89e3\u6790\u5668<\/p>\n<h4>2\u3001\u6ce8\u610f<\/h4>\n<p>1\u3001\u56e0\u4e3avue.runtime.xxx.js\u6ca1\u6709\u6a21\u677f\u89e3\u6790\u5668\uff0c\u6240\u4ee5\u4e0d\u80fd\u4f7f\u7528template\u914d\u7f6e\u9879\uff0c\u9700\u8981\u4f7f\u7528render\u51fd\u6570\u63a5\u6536\u5230\u7684createElement\u51fd\u6570\u53bb\u6307\u5b9a\u5177\u4f53\u5185\u5bb9<\/p>\n<h3>4\u3001vue.config.js\u914d\u7f6e\u6587\u4ef6<\/h3>\n<ol>\n<li>\u4f7f\u7528vue inspect &gt; output.js\u53ef\u4ee5\u67e5\u770b\u5230Vue\u811a\u624b\u67b6\u7684\u9ed8\u8ba4\u914d\u7f6e\u3002<\/li>\n<li>\u4f7f\u7528vue.config.js\u53ef\u4ee5\u5bf9\u811a\u624b\u67b6\u8fdb\u884c\u4e2a\u6027\u5316\u5b9a\u5236\uff0c\u8be6\u60c5\u89c1\uff1a<a href=\"https:\/\/cli.vuejs.org\/zh\">https:\/\/cli.vuejs.org\/zh<\/a><\/li>\n<\/ol>\n<h2>3\u3001ref\u5c5e\u6027<\/h2>\n<ol>\n<li>\u88ab\u7528\u6765\u7ed9\u5143\u7d20\u6216\u5b50\u7ec4\u4ef6\u6ce8\u518c\u5f15\u7528\u4fe1\u606f\uff08id\u7684\u66ff\u4ee3\u8005\uff09<\/li>\n<li>\u5e94\u7528\u5728html\u6807\u7b7e\u4e0a\u83b7\u53d6\u7684\u662f\u771f\u5b9eDOM\u5143\u7d20\uff0c\u5e94\u7528\u5728\u7ec4\u4ef6\u6807\u7b7e\u4e0a\u662f\u7ec4\u4ef6\u5b9e\u4f8b\u5bf9\u8c61\uff08vc\uff09<\/li>\n<li>\u4f7f\u7528\u65b9\u5f0f<\/li>\n<\/ol>\n<pre><code>\u6253\u6807\u8bc6\uff1a```&lt;h1 ref=&quot;xxx&quot;&gt;.....&lt;\/h1&gt;``` \n       ```&lt;School ref=&quot;xxx&quot;&gt;&lt;\/School&gt;```\n\u83b7\u53d6\uff1a```this.$refs.xxx```<\/code><\/pre>\n<h2>4\u3001props\u914d\u7f6e\u9879<\/h2>\n<h3>1\u3001\u529f\u80fd<\/h3>\n<ol>\n<li>\u8ba9\u7ec4\u4ef6\u63a5\u53d7\u5916\u90e8\u4f20\u8fc7\u6765\u7684\u6570\u636e<\/li>\n<\/ol>\n<h3>2\u3001\u4f7f\u7528<\/h3>\n<h4>1\u3001\u4f20\u9012\u6570\u636e<\/h4>\n<pre><code>&lt;Demo name=&quot;xxx&quot;&gt;<\/code><\/pre>\n<h4>2\u3001\u63a5\u53d7\u6570\u636e<\/h4>\n<p>1\u3001\u65b9\u6cd5\u4e00(\u53ea\u63a5\u6536)<\/p>\n<pre><code>props:[&#039;name&#039;]<\/code><\/pre>\n<p>2\u3001\u65b9\u6cd5\u4e8c(\u9650\u5236\u7c7b\u578b)<\/p>\n<pre><code>props:{\n    name:String\n}<\/code><\/pre>\n<p>3\u3001\u65b9\u6cd5\u4e09(\u9650\u5236\u7c7b\u578b\u3001\u9650\u5236\u5fc5\u8981\u6027\u3001\u6307\u5b9a\u9ed8\u8ba4\u503c)<\/p>\n<pre><code>props:{\n    name:{\n        type:Stirng,\n        required:true,\n        default:&#039;xxx&#039;\n    }\n}<\/code><\/pre>\n<h3>3\u3001\u6ce8\u610f<\/h3>\n<p>1\u3001props\u53ea\u8bfb\uff0cvue\u5e95\u5c42\u903b\u8f91\u4f1a\u76d1\u89c6\u4f60\u5bf9props\u7684\u4fee\u6539\uff0c\u5982\u679c\u8fdb\u884c\u4e86\u4fee\u6539\uff0c\u5c31\u4f1a\u53d1\u51fa\u8b66\u544a\uff0c\u82e5\u4e1a\u52a1\u9700\u6c42\u786e\u5b9e\u9700\u8981\u4fee\u6539\uff0c\u90a3\u5c31\u8d4b\u503cprops\u7684\u5185\u5bb9\u5230data\u4e2d\uff0c\u7136\u540e\u53bb\u4fee\u6539data\u7684\u6570\u636e<\/p>\n<p>2\u3001props\u4e2d\u7684\u65b9\u6cd5\u4e09\uff0crequired\u548cdefault\u5c3d\u91cf\u4e0d\u8981\u5199\u5728\u4e00\u8d77<\/p>\n<h2>5\u3001mixin\uff08\u6df7\u5165\uff09<\/h2>\n<h3>1\u3001\u529f\u80fd<\/h3>\n<p>1\u3001\u53ef\u4ee5\u628a\u591a\u4e2a\u7ec4\u4ef6\u5171\u7528\u7684\u914d\u7f6e\u63d0\u53d6\u6210\u4e00\u4e2a\u6df7\u5165\u5bf9\u8c61<\/p>\n<p>2\u3001\u53ef\u4ee5\u7406\u89e3\u4e3ajava\u4e2d\u7684\u5c01\u88c5<\/p>\n<h3>2\u3001\u4f7f\u7528\u683c\u5f0f<\/h3>\n<p>1\u3001\u5b9a\u4e49\u6df7\u5408<\/p>\n<pre><code>{\n    data(){...},\n    methods:{...},\n    ......\n}<\/code><\/pre>\n<p>2\u3001\u4f7f\u7528\u6df7\u5408<\/p>\n<pre><code>\u5168\u5c40\u6df7\u5408\uff1aVue.mixin(xxx)\n\u5c40\u90e8\u6df7\u5408\uff1amixins:[&#039;xxx&#039;]<\/code><\/pre>\n<h2>6\u3001\u63d2\u4ef6<\/h2>\n<h3>1\u3001\u529f\u80fd<\/h3>\n<p>1\u3001\u7528\u4e8e\u589e\u5f3aVue<\/p>\n<h3>2\u3001\u672c\u8d28<\/h3>\n<p>1\u3001\u5305\u542binstall\u65b9\u6cd5\u7684\u4e00\u4e2a\u5927\u5bf9\u8c61\uff0cinstall\u7684\u7b2c\u4e00\u4e2a\u53c2\u6570\u662fvue\uff0c\u7b2c\u4e8c\u4e2a\u4ee5\u540e\u7684\u53c2\u6570\u662f\u63d2\u4ef6\u4f7f\u7528\u8005\u4f20\u9012\u7684\u6570\u636e<\/p>\n<h3>3\u3001\u5b9a\u4e49\u63d2\u4ef6<\/h3>\n<pre><code class=\"language-js\">\u5bf9\u8c61.install = function (Vue, options) {\n    \/\/ 1. \u6dfb\u52a0\u5168\u5c40\u8fc7\u6ee4\u5668\n    Vue.filter(....)\n\n    \/\/ 2. \u6dfb\u52a0\u5168\u5c40\u6307\u4ee4\n    Vue.directive(....)\n\n    \/\/ 3. \u914d\u7f6e\u5168\u5c40\u6df7\u5165(\u5408)\n    Vue.mixin(....)\n\n    \/\/ 4. \u6dfb\u52a0\u5b9e\u4f8b\u65b9\u6cd5\n    Vue.prototype.$myMethod = function () {...}\n    Vue.prototype.$myProperty = xxxx\n}<\/code><\/pre>\n<h3>4\u3001\u4f7f\u7528\u63d2\u4ef6<\/h3>\n<p>1\u3001\u683c\u5f0f<\/p>\n<pre><code>Vue.use()<\/code><\/pre>\n<h2>7\u3001TodoList\u6848\u4f8b<\/h2>\n<h3>1\u3001\u5b9e\u73b0\u6570\u636e\u7684\u6dfb\u52a0<\/h3>\n<p>1\u3001\u91cd\u70b9<div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/image-20231113224737944.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/image-20231113224737944.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20231113224737944\" \/><\/div><\/p>\n<p>2\u3001\u5c31\u662fHeader\u63a5\u6536\u6570\u636e\uff0c\u4f20\u9012\u7ed9List\u4e2d\u7684item\u663e\u793a\uff0c<\/p>\n<p>\u2460\u5c31\u9700\u8981\u628a\u6570\u636e\u653e\u5230App\u4e2d\uff0c\u7136\u540eApp\u518d\u628a\u6570\u636e\u4f20\u9012\u7ed9list\u4e2d\u7684item<\/p>\n<p>\u2461Header\u65e0\u6cd5\u76f4\u63a5\u7ed9List\uff08\u76ee\u524d\u6240\u5b66\uff09<\/p>\n<p>\u2462App\u7ed9Header\u4e2d\u4f20\u5165\u4e86\u4e00\u4e2a\u51fd\u6570<\/p>\n<p>\u2463\u5728Header\u6240\u9700\u8981\u7684\u65f6\u5019\uff0c\u518d\u4f20\u7ed9App\u7ec4\u4ef6<\/p>\n<h2>8\u3001\u603b\u7ed3TodoList\u6848\u4f8b<\/h2>\n<h3>1\u3001\u7ec4\u4ef6\u5316\u7f16\u7801\u6d41\u7a0b\uff1a<\/h3>\n<p>\u200b   (1).\u62c6\u5206\u9759\u6001\u7ec4\u4ef6\uff1a\u7ec4\u4ef6\u8981\u6309\u7167\u529f\u80fd\u70b9\u62c6\u5206\uff0c\u547d\u540d\u4e0d\u8981\u4e0ehtml\u5143\u7d20\u51b2\u7a81\u3002<\/p>\n<p>\u200b   (2).\u5b9e\u73b0\u52a8\u6001\u7ec4\u4ef6\uff1a\u8003\u8651\u597d\u6570\u636e\u7684\u5b58\u653e\u4f4d\u7f6e\uff0c\u6570\u636e\u662f\u4e00\u4e2a\u7ec4\u4ef6\u5728\u7528\uff0c\u8fd8\u662f\u4e00\u4e9b\u7ec4\u4ef6\u5728\u7528\uff1a<\/p>\n<p>\u200b           1).\u4e00\u4e2a\u7ec4\u4ef6\u5728\u7528\uff1a\u653e\u5728\u7ec4\u4ef6\u81ea\u8eab\u5373\u53ef\u3002<\/p>\n<p>\u200b           2). \u4e00\u4e9b\u7ec4\u4ef6\u5728\u7528\uff1a\u653e\u5728\u4ed6\u4eec\u5171\u540c\u7684\u7236\u7ec4\u4ef6\u4e0a\uff08<span style=\"color:red\">\u72b6\u6001\u63d0\u5347<\/span>\uff09\u3002<\/p>\n<p>\u200b   (3).\u5b9e\u73b0\u4ea4\u4e92\uff1a\u4ece\u7ed1\u5b9a\u4e8b\u4ef6\u5f00\u59cb\u3002<\/p>\n<h3>2\u3001props\u9002\u7528\u4e8e\uff1a<\/h3>\n<p>\u200b   (1).\u7236\u7ec4\u4ef6 ==&gt; \u5b50\u7ec4\u4ef6 \u901a\u4fe1<\/p>\n<p>\u200b   (2).\u5b50\u7ec4\u4ef6 ==&gt; \u7236\u7ec4\u4ef6 \u901a\u4fe1\uff08\u8981\u6c42\u7236\u5148\u7ed9\u5b50\u4e00\u4e2a\u51fd\u6570\uff09<\/p>\n<ol>\n<li>\n<p>\u4f7f\u7528v-model\u65f6\u8981\u5207\u8bb0\uff1av-model\u7ed1\u5b9a\u7684\u503c\u4e0d\u80fd\u662fprops\u4f20\u8fc7\u6765\u7684\u503c\uff0c\u56e0\u4e3aprops\u662f\u4e0d\u53ef\u4ee5\u4fee\u6539\u7684\uff01<\/p>\n<\/li>\n<li>\n<p>props\u4f20\u8fc7\u6765\u7684\u82e5\u662f\u5bf9\u8c61\u7c7b\u578b\u7684\u503c\uff0c\u4fee\u6539\u5bf9\u8c61\u4e2d\u7684\u5c5e\u6027\u65f6Vue\u4e0d\u4f1a\u62a5\u9519\uff0c\u4f46\u4e0d\u63a8\u8350\u8fd9\u6837\u505a\u3002<\/p>\n<\/li>\n<\/ol>\n<h2>9\u3001webStorage<\/h2>\n<h3>1\u3001\u5185\u5bb9<\/h3>\n<ol>\n<li>\u5b58\u50a8\u5185\u5bb9\u5927\u5c0f\u4e00\u822c\u652f\u63015MB\u5de6\u53f3\uff08\u4e0d\u540c\u6d4f\u89c8\u5668\u53ef\u80fd\u8fd8\u4e0d\u4e00\u6837\uff09<\/li>\n<li>\u6d4f\u89c8\u5668\u7aef\u901a\u8fc7 Window.sessionStorage \u548c Window.localStorage \u5c5e\u6027\u6765\u5b9e\u73b0\u672c\u5730\u5b58\u50a8\u673a\u5236\u3002<\/li>\n<\/ol>\n<h3>2\u3001\u76f8\u5173API<\/h3>\n<ol>\n<li>\n<p><code><code>xxxxxStorage.setItem(&#039;key&#039;, &#039;value&#039;);<\/code><\/code><br \/>\n\u8be5\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u952e\u548c\u503c\u4f5c\u4e3a\u53c2\u6570\uff0c\u4f1a\u628a\u952e\u503c\u5bf9\u6dfb\u52a0\u5230\u5b58\u50a8\u4e2d\uff0c\u5982\u679c\u952e\u540d\u5b58\u5728\uff0c\u5219\u66f4\u65b0\u5176\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n<\/li>\n<li>\n<p><code><code>xxxxxStorage.getItem(&#039;person&#039;);<\/code><\/code><\/p>\n<p>\u200b        \u8be5\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u952e\u540d\u4f5c\u4e3a\u53c2\u6570\uff0c\u8fd4\u56de\u952e\u540d\u5bf9\u5e94\u7684\u503c\u3002<\/p>\n<\/li>\n<li>\n<p><code><code>xxxxxStorage.removeItem(&#039;key&#039;);<\/code><\/code><\/p>\n<p>\u200b        \u8be5\u65b9\u6cd5\u63a5\u53d7\u4e00\u4e2a\u952e\u540d\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u628a\u8be5\u952e\u540d\u4ece\u5b58\u50a8\u4e2d\u5220\u9664\u3002<\/p>\n<\/li>\n<li>\n<p><code><code> xxxxxStorage.clear()<\/code><\/code><\/p>\n<p>\u200b        \u8be5\u65b9\u6cd5\u4f1a\u6e05\u7a7a\u5b58\u50a8\u4e2d\u7684\u6240\u6709\u6570\u636e\u3002<\/p>\n<\/li>\n<\/ol>\n<h3>3\u3001\u5907\u6ce8<\/h3>\n<ol>\n<li>SessionStorage\u5b58\u50a8\u7684\u5185\u5bb9\u4f1a\u968f\u7740\u6d4f\u89c8\u5668\u7a97\u53e3\u5173\u95ed\u800c\u6d88\u5931\u3002<\/li>\n<li>LocalStorage\u5b58\u50a8\u7684\u5185\u5bb9\uff0c\u9700\u8981\u624b\u52a8\u6e05\u9664\u624d\u4f1a\u6d88\u5931\u3002<\/li>\n<li><code><code>xxxxxStorage.getItem(xxx)<\/code><\/code>\u5982\u679cxxx\u5bf9\u5e94\u7684value\u83b7\u53d6\u4e0d\u5230\uff0c\u90a3\u4e48getItem\u7684\u8fd4\u56de\u503c\u662fnull\u3002<\/li>\n<li><code><code>JSON.parse(null)<\/code><\/code>\u7684\u7ed3\u679c\u4f9d\u7136\u662fnull\u3002<\/li>\n<\/ol>\n<h2>10\u3001\u7ec4\u4ef6\u81ea\u5b9a\u4e49\u4e8b\u4ef6<\/h2>\n<h3>1\u3001\u5185\u5bb9<\/h3>\n<p>1\u3001\u662f\u4ec0\u4e48\uff1a\u4e00\u79cd\u7ec4\u4ef6\u95f4\u901a\u4fe1\u7684\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\uff1a<strong style=\"color:red\">\u5b50\u7ec4\u4ef6 ===&gt; \u7236\u7ec4\u4ef6<\/strong><\/p>\n<p>2\u3001\u4f7f\u7528\u573a\u666f\uff1aA\u662f\u7236\u7ec4\u4ef6\uff0cB\u662f\u5b50\u7ec4\u4ef6\uff0cB\u60f3\u7ed9A\u4f20\u6570\u636e\uff0c\u90a3\u4e48\u5c31\u8981\u5728A\u4e2d\u7ed9B\u7ed1\u5b9a\u81ea\u5b9a\u4e49\u4e8b\u4ef6\uff08<span style=\"color:red\">\u4e8b\u4ef6\u7684\u56de\u8c03\u5728A\u4e2d<\/span>\uff09\u3002<\/p>\n<h3>2\u3001\u7ed1\u5b9a\u81ea\u5b9a\u4e49\u4e8b\u4ef6<\/h3>\n<h4>1\u3001\u65b9\u6cd5\u4e00<\/h4>\n<p>1\u3001\u5728\u7236\u7ec4\u4ef6\u4e2d\uff1a<\/p>\n<pre><code>&lt;Demo @atguigu=&quot;test&quot;\/&gt; \u6216 &lt;Demo v-on:atguigu=&quot;test&quot;\/&gt;<\/code><\/pre>\n<h4>2\u3001\u65b9\u6cd5\u4e8c<\/h4>\n<p>1\u3001\u5728\u7236\u7ec4\u4ef6\u4e2d\uff1a<\/p>\n<pre><code class=\"language-js\">&lt;Demo ref=&quot;demo&quot;\/&gt;\n......\nmounted(){\n   this.$refs.xxx.$on(&#039;atguigu&#039;,this.test)\n}<\/code><\/pre>\n<h4>3\u3001\u6ce8\u610f<\/h4>\n<p>1\u3001\u82e5\u60f3\u8ba9\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u53ea\u80fd\u89e6\u53d1\u4e00\u6b21\uff0c\u53ef\u4ee5\u4f7f\u7528<code><code>once<\/code>`<code>\u4fee\u9970\u7b26\uff0c\u6216<\/code>`<code>$once<\/code><\/code>\u65b9\u6cd5\u3002<\/p>\n<h3>3\u3001\u89e6\u53d1\/\u89e3\u7ed1\u81ea\u5b9a\u4e49\u4e8b\u4ef6<\/h3>\n<p>1\u3001\u89e6\u53d1\u81ea\u5b9a\u4e49\u4e8b\u4ef6\uff1a<\/p>\n<pre><code>this.$emit(&#039;atguigu&#039;,\u6570\u636e)<\/code><\/pre>\n<p>2\u3001\u89e3\u7ed1\u81ea\u5b9a\u4e49\u4e8b\u4ef6\uff1a<\/p>\n<pre><code>this.$off(&#039;atguigu&#039;)<\/code><\/pre>\n<p>3\u3001\u7ec4\u4ef6\u4e0a\u4e5f\u53ef\u4ee5\u7ed1\u5b9a\u539f\u751fDOM\u4e8b\u4ef6\uff0c\u9700\u8981\u4f7f\u7528<code><code>native<\/code><\/code>\u4fee\u9970\u7b26<\/p>\n<h3>4\u3001\u6ce8\u610f<\/h3>\n<p>1\u3001\u901a\u8fc7<code><code>this.$refs.xxx.$on(&#039;atguigu&#039;,\u56de\u8c03)<\/code><\/code>\u7ed1\u5b9a\u81ea\u5b9a\u4e49\u4e8b\u4ef6\u65f6\uff0c\u56de\u8c03<span style=\"color:red\">\u8981\u4e48\u914d\u7f6e\u5728methods\u4e2d<\/span>\uff0c<span style=\"color:red\">\u8981\u4e48\u7528\u7bad\u5934\u51fd\u6570<\/span>\uff0c\u5426\u5219this\u6307\u5411\u4f1a\u51fa\u95ee\u9898\uff01<\/p>\n<h2>11\u3001\u5168\u5c40\u4e8b\u4ef6\u603b\u7ebf<\/h2>\n<h3>1\u3001\u662f\u4ec0\u4e48<\/h3>\n<h4>1\u3001\u4e00\u79cd\u7ec4\u4ef6\u95f4\u901a\u4fe1\u7684\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e<span style=\"color:red\">\u4efb\u610f\u7ec4\u4ef6\u95f4\u901a\u4fe1<\/span>\u3002<\/h4>\n<h3>2\u3001\u600e\u4e48\u505a<\/h3>\n<h4>1\u3001\u5b89\u88c5\u5168\u5c40\u4e8b\u4ef6\u603b\u7ebf<\/h4>\n<pre><code class=\"language-js\">new Vue({\n    ......\n    beforeCreate() {\n        Vue.prototype.$bus = this \/\/\u5b89\u88c5\u5168\u5c40\u4e8b\u4ef6\u603b\u7ebf\uff0c$bus\u5c31\u662f\u5f53\u524d\u5e94\u7528\u7684vm\n    },\n    ......\n}) <\/code><\/pre>\n<h4>2\u3001\u4f7f\u7528\u4e8b\u4ef6\u603b\u7ebf<\/h4>\n<p>1\u3001\u63a5\u6536\u6570\u636e\uff1aA\u7ec4\u4ef6\u60f3\u63a5\u6536\u6570\u636e\uff0c\u5219\u5728A\u7ec4\u4ef6\u4e2d\u7ed9$bus\u7ed1\u5b9a\u81ea\u5b9a\u4e49\u4e8b\u4ef6\uff0c\u4e8b\u4ef6\u7684<span style=\"color:red\">\u56de\u8c03\u7559\u5728A\u7ec4\u4ef6\u81ea\u8eab\u3002<\/span><\/p>\n<p>2\u3001\u683c\u5f0f<\/p>\n<pre><code class=\"language-js\">methods(){\n  demo(data){......}\n}\n......\nmounted() {\n  this.$bus.$on(&#039;xxxx&#039;,this.demo)\n}<\/code><\/pre>\n<p>3\u3001\u63d0\u4f9b\u6570\u636e\uff1athis.$bus.$emit('xxxx',\u6570\u636e)<\/p>\n<h3>3\u3001\u6ce8\u610f<\/h3>\n<p>1\u3001\u6700\u597d\u5728beforeDestroy\u94a9\u5b50\u4e2d\uff0c\u7528$off\u53bb\u89e3\u7ed1<span style=\"color:red\">\u5f53\u524d\u7ec4\u4ef6\u6240\u7528\u5230\u7684<\/span>\u4e8b\u4ef6\u3002<\/p>\n<h3>4\u3001TodoList\u4f8b\u5b50<\/h3>\n<p>1\u3001App.vue<\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n\n  &lt;div id=&quot;root&quot;&gt;\n  &lt;div class=&quot;todo-container&quot;&gt;\n    &lt;div class=&quot;todo-wrap&quot;&gt;\n      &lt;MyHeader @addTodo=&quot;addTodo&quot;\/&gt;\n      &lt;MyList :todos=&quot;todos&quot;  \/&gt;\n      &lt;MyFooter :todos=&quot;todos&quot; @checkAllTodo=&quot;checkAllTodo&quot; @clearAllTodo=&quot;clearAllTodo&quot;\/&gt;\n    &lt;\/div&gt;\n  &lt;\/div&gt;\n  &lt;\/div&gt;\n\n&lt;\/template&gt;\n\n&lt;script &gt;\n  import MyList from &quot;.\/components\/MyList.vue&quot;;\n  import MyFooter from &quot;.\/components\/MyFooter.vue&quot;;\n  import MyHeader from &#039;.\/components\/MyHeader.vue&#039;;\n\n  export default {\n    name:&#039;App&#039;,\n    components: { \n      MyHeader,\n      MyFooter,\n      MyList\n    },\n    data(){\n      return{\n        \/\/\u7531\u4e8etodos\u662fMyHeader\u7ec4\u4ef6\u548cMyFooter\u7ec4\u4ef6\u90fd\u5728\u4f7f\u7528\uff0c\u6240\u4ee5\u653e\u5728App\u4e2d\uff08\u72b6\u6001\u63d0\u5347\uff09\n        todos:JSON.parse(localStorage.getItem(&#039;todos&#039;)) || []\n\n      }\n\n        },\n    methods:{\n      \/\/ \u8fd9\u4e2a\u65b9\u6cd5\u5c31\u662f\u6dfb\u52a0\u4e00\u4e2atodoObj\n      addTodo(todoObj){\n        this.todos.unshift(todoObj)\n      },\n      \/\/ \u52fe\u9009or\u53d6\u6d88\u52fe\u9009\u4e00\u4e2atodo\n      checkTodo(id){\n        this.todos.forEach((todo)=&gt;{\n          if(todo.id===id){\n            todo.done = !todo.done\n          }\n        })\n      },\n\n      \/\/\u5220\u9664\u4e00\u4e2atodo\n      deleteTodo(id) {\n        this.todos = this.todos.filter( todo =&gt; todo.id !== id )\n      },\n      \/\/ \u5168\u9009\u6216\u5168\u4e0d\u9009\n      checkAllTodo(done){\n        this.todos.forEach((todo)=&gt;{\n          todo.done = done\n        })\n      },\n      \/\/ \u5220\u9664\u6240\u6709\u7684todo\n      clearAllTodo(){\n        this.todos =this.todos.filter((todo)=&gt;{\n          return !todo.done;\n        })\n      }\n    },\n    watch:{\n      todos:{\n        deep:true,\n        handler(value){\n          localStorage.setItem(&#039;todos&#039;,JSON.stringify(value))\n        }\n      }\n    },\n    mounted(){\n      this.$bus.$on(&#039;checkTodo&#039;,this.checkTodo),\n      this.$bus.$on(&#039;deleteTodo&#039;,this.deleteTodo)\n    },\n    beforeDestory(){\n      this.$.bus.$off(&#039;checkTodo&#039;)\n      this.$.bus.$off(&#039;deleteTodo&#039;)\n    }\n\n  };\n&lt;\/script&gt;\n\n&lt;style&gt;\n\/*base*\/\nbody {\n  background: #fff;\n}\n\n.btn {\n  display: inline-block;\n  padding: 4px 12px;\n  margin-bottom: 0;\n  font-size: 14px;\n  line-height: 20px;\n  text-align: center;\n  vertical-align: middle;\n  cursor: pointer;\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2),\n    0 1px 2px rgba(0, 0, 0, 0.05);\n  border-radius: 4px;\n}\n\n.btn-danger {\n  color: #fff;\n  background-color: #da4f49;\n  border: 1px solid #bd362f;\n}\n\n.btn-danger:hover {\n  color: #fff;\n  background-color: #bd362f;\n}\n\n.btn:focus {\n  outline: none;\n}\n\n.todo-container {\n  width: 600px;\n  margin: 0 auto;\n}\n.todo-container .todo-wrap {\n  padding: 10px;\n  border: 1px solid #ddd;\n  border-radius: 5px;\n}\n\n&lt;\/style&gt;<\/code><\/pre>\n<p>2\u3001MyItem.vue<\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n    &lt;li&gt;\n    &lt;label&gt;\n        &lt;input type=&quot;checkbox&quot; :checked=&quot;todo.done&quot; @change=&quot;handleCheck(todo.id)&quot;\/&gt;\n        &lt;!-- &lt;input type=&quot;checkbox&quot; v-model=&quot;todo.done&quot;\/&gt; --&gt;\n        &lt;span&gt;{{todo.title}}&lt;\/span&gt;\n    &lt;\/label&gt;\n    &lt;button class=&quot;btn btn-danger&quot; @click=&quot;handleDelet(todo.id)&quot;&gt;\u5220\u9664&lt;\/button&gt;\n    &lt;\/li&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\n    export default {\n        name:&#039;MyItem&#039;,\n        \/\/ \u58f0\u660e\u63a5\u6536todo\u6570\u636e\n        props:[&#039;todo&#039;],\n        methods:{\n          handleCheck(id){\n            \/\/ \/\/ console.log(id)\n\n            \/\/ \u901a\u77e5App\u7ec4\u4ef6\u5c06\u5bf9\u5e94\u7684todo\u5bf9\u8c61\u7684done\u503c\u53d6\u53cd\n            \/\/ this.checkTodo(id);\n            this.$bus.$emit(&#039;checkTodo&#039;,id)\n          },\n          \/\/ \u5220\u9664item\n          handleDelet(id){\n            if(confirm(&quot;\u786e\u5b9a\u5220\u9664\u5417\uff1f&quot;)){\n              \/\/ this.deleteTodo(id)\n              this.$bus.$emit(&#039;deleteTodo&#039;,id)\n            }\n            \/\/ console.log(id)\n          }\n        }\n    }\n&lt;\/script&gt;\n\n&lt;style&gt;\n    \/*item*\/\nli {\n  list-style: none;\n  height: 36px;\n  line-height: 36px;\n  padding: 0 5px;\n  border-bottom: 1px solid #ddd;\n}\n\nli label {\n  float: left;\n  cursor: pointer;\n}\n\nli label li input {\n  vertical-align: middle;\n  margin-right: 6px;\n  position: relative;\n  top: -1px;\n}\n\nli button {\n  float: right;\n  display: none;\n  margin-top: 3px;\n}\n\nli:before {\n  content: initial;\n}\n\nli:last-child {\n  border-bottom: none;\n}\nli:hover{\n  background-color: #ddd;\n}\nli:hover button{\n  display: block;\n}\n&lt;\/style&gt;<\/code><\/pre>\n<p>3\u3001MyList.vue<\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n    &lt;ul class=&quot;todo-main&quot;&gt;\n        &lt;MyItem \n        v-for=&quot;todoObj in todos&quot; \n        :key=&quot;todoObj.id&quot; \n        :todo=&quot;todoObj&quot;\n        \/&gt;\n\n    &lt;\/ul&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nimport MyItem from &#039;.\/MyItem.vue&#039;\n\n    export default {\n        name:&#039;MyList&#039;,\n        components:{\n            MyItem\n        },\n        props:[&#039;todos&#039;]\n    }\n&lt;\/script&gt;\n\n&lt;style&gt;\n    \/*main*\/\n.todo-main {\n  margin-left: 0px;\n  border: 1px solid #ddd;\n  border-radius: 2px;\n  padding: 0px;\n}\n\n.todo-empty {\n  height: 40px;\n  line-height: 40px;\n  border: 1px solid #ddd;\n  border-radius: 2px;\n  padding-left: 5px;\n  margin-top: 10px;\n}\n&lt;\/style&gt;<\/code><\/pre>\n<h2>12\u3001\u6d88\u606f\u8ba2\u9605\u4e0e\u53d1\u5e03\uff08pubsub\uff09<\/h2>\n<h3>1\u3001\u662f\u4ec0\u4e48<\/h3>\n<p>1\u3001\u4e00\u79cd\u7ec4\u4ef6\u95f4\u901a\u4fe1\u7684\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e<span style=\"color:red\">\u4efb\u610f\u7ec4\u4ef6\u95f4\u901a\u4fe1<\/span>\u3002<\/p>\n<p>2\u3001\u662f\u4e2a\u63d2\u4ef6\uff0c\u76f8\u5f53\u4e8ejar\u5305<\/p>\n<h3>2\u3001\u600e\u4e48\u7528<\/h3>\n<h4>1\u3001\u5b89\u88c5<\/h4>\n<p>1\u3001\u6b65\u9aa4<\/p>\n<pre><code>npm i pubsub-js<\/code><\/pre>\n<h4>2\u3001\u4f7f\u7528<\/h4>\n<p>1\u3001\u5f15\u5165<\/p>\n<pre><code>import pubsub from &#039;pubsub-js&#039;<\/code><\/pre>\n<p>2\u3001\u63a5\u53d7\u6570\u636e\uff1aA\u7ec4\u4ef6\u60f3\u63a5\u6536\u6570\u636e\uff0c\u5219\u5728A\u7ec4\u4ef6\u4e2d\u8ba2\u9605\u6d88\u606f\uff0c\u8ba2\u9605\u7684<span style=\"color:red\">\u56de\u8c03\u7559\u5728A\u7ec4\u4ef6\u81ea\u8eab\u3002<\/span><\/p>\n<p>3\u3001\u683c\u5f0f<\/p>\n<pre><code class=\"language-js\">methods(){\n  demo(data){......}\n}\n......\nmounted() {\n  this.pid = pubsub.subscribe(&#039;xxx&#039;,this.demo) \/\/\u8ba2\u9605\u6d88\u606f\n}<\/code><\/pre>\n<p>4\u3001\u63d0\u4f9b\u6570\u636e<\/p>\n<pre><code>pubsub.publish(&#039;xxx&#039;,\u6570\u636e)<\/code><\/pre>\n<h3>3\u3001\u6ce8\u610f\u4e8b\u9879<\/h3>\n<p>1\u3001\u6700\u597d\u5728beforeDestroy\u94a9\u5b50\u4e2d\uff0c\u7528<code><code>PubSub.unsubscribe(pid)<\/code><\/code>\u53bb<span style=\"color:red\">\u53d6\u6d88\u8ba2\u9605\u3002<\/span><\/p>\n<p>2\u3001\u4e00\u822c\u8fd8\u662f\u4f7f\u7528vue\u7684\u5168\u5c40\u603b\u7ebf\uff0c\u56e0\u4e3a\u4ed6\u4eec\u4e24\u4e2a\u4e00\u6837\uff0c\u4f46\u662fpubsub\u9700\u8981\u5904\u7406this\uff0c\u8fd9\u4e2a\u5305\u4e0d\u662fvue\u4e2d\u7684this\uff0c\u6240\u4ee5\u53ef\u80fd\u4f1a\u51fa\u73b0\u95ee\u9898\u3002<\/p>\n<h2>13\u3001nextTick<\/h2>\n<h3>1\u3001\u662f\u4ec0\u4e48<\/h3>\n<p>1\u3001\u662f\u4e00\u4e2avue\u4e2d\u7684\u4e00\u4e2aapi\u51fd\u6570<\/p>\n<p>2\u3001\u4f5c\u7528\uff1a\u5728\u4e0b\u4e00\u6b21 DOM \u66f4\u65b0\u7ed3\u675f\u540e\u6267\u884c\u5176\u6307\u5b9a\u7684\u56de\u8c03\u3002<\/p>\n<h3>2\u3001\u600e\u4e48\u7528<\/h3>\n<p>1\u3001\u4ec0\u4e48\u65f6\u5019\u7528\uff1a\u5f53\u6539\u53d8\u6570\u636e\u540e\uff0c\u8981\u57fa\u4e8e\u66f4\u65b0\u540e\u7684\u65b0DOM\u8fdb\u884c\u67d0\u4e9b\u64cd\u4f5c\u65f6\uff0c\u8981\u5728nextTick\u6240\u6307\u5b9a\u7684\u56de\u8c03\u51fd\u6570\u4e2d\u6267\u884c\u3002<\/p>\n<h2>14\u3001Vue\u5c01\u88c5\u7684\u8fc7\u5ea6\u4e0e\u52a8\u753b<\/h2>\n<h3>1\u3001\u662f\u4ec0\u4e48<\/h3>\n<p>1\u3001\u5c31\u662f\u8fc7\u5ea6\u7684\u52a8\u753b<\/p>\n<h3>2\u3001\u600e\u4e48\u7528<\/h3>\n<h4>1\u3001\u4f5c\u7528<\/h4>\n<p>1\u3001\u5728\u63d2\u5165\u3001\u66f4\u65b0\u6216\u79fb\u9664 DOM\u5143\u7d20\u65f6\uff0c\u5728\u5408\u9002\u7684\u65f6\u5019\u7ed9\u5143\u7d20\u6dfb\u52a0\u6837\u5f0f\u7c7b\u540d\u3002<\/p>\n<h4>2\u3001\u56fe\u793a\uff08\u5b98\u7f51\uff09<\/h4>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/image-20231118224523644.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"http:\/\/zyg.luchers.cn\/wp-content\/uploads\/2024\/04\/image-20231118224523644.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"image-20231118224523644\" \/><\/div><\/p>\n<h4>3\u3001\u5199\u6cd5<\/h4>\n<h5>1\u3001\u51c6\u5907\u597d\u6837\u5f0f<\/h5>\n<p>1\u3001\u5143\u7d20\u8fdb\u5165\u7684\u6837\u5f0f<\/p>\n<pre><code>v-enter\uff1a\u8fdb\u5165\u7684\u8d77\u70b9\nv-enter-active\uff1a\u8fdb\u5165\u7684\u8fc7\u7a0b\u4e2d\nv-enter-to\uff1a\u8fdb\u5165\u7684\u7ec8\u70b9<\/code><\/pre>\n<p>2\u3001\u5143\u7d20\u79bb\u5f00\u7684\u6837\u5f0f<\/p>\n<pre><code>v-leave\uff1a\u79bb\u5f00\u7684\u8d77\u70b9\nv-leave-active\uff1a\u79bb\u5f00\u7684\u8fc7\u7a0b\nv-leave-to\uff1a\u79bb\u5f00\u7684\u7ec8\u70b9<\/code><\/pre>\n<h5>2\u3001\u4f7f\u7528<code><code>&lt;transition&gt;<\/code><\/code>\u5305\u88f9\u8981\u8fc7\u5ea6\u7684\u5143\u7d20\uff0c\u5e76\u914d\u7f6ename\u5c5e\u6027<\/h5>\n<p>1\u3001<\/p>\n<pre><code class=\"language-vue\">&lt;transition name=&quot;hello&quot;&gt;\n    &lt;h1 v-show=&quot;isShow&quot;&gt;\u4f60\u597d\u554a\uff01&lt;\/h1&gt;\n&lt;\/transition&gt;<\/code><\/pre>\n<h4>4\u3001\u5907\u6ce8<\/h4>\n<p>1\u3001\u82e5\u6709\u591a\u4e2a\u5143\u7d20\u9700\u8981\u8fc7\u5ea6\uff0c\u5219\u9700\u8981\u4f7f\u7528\uff1a<code><code>&lt;transition-group&gt;<\/code>`<code>\uff0c\u4e14\u6bcf\u4e2a\u5143\u7d20\u90fd\u8981\u6307\u5b9a<\/code>`<code>key<\/code><\/code>\u503c\u3002<\/p>\n<h4>5\u3001\u4f8b\u5b50<\/h4>\n<pre><code class=\"language-vue\">&lt;template&gt;\n    &lt;div&gt;\n        &lt;button @click=&quot;isShow = !isShow&quot;&gt;\u663e\u793a\/\u9690\u85cf&lt;\/button&gt;\n        &lt;transition-group name=&quot;hello&quot; appear&gt;\n            &lt;h1 v-show=&quot;!isShow&quot; key=&quot;1&quot;&gt;\u4f60\u597d\u554a\uff01&lt;\/h1&gt;\n            &lt;h1 v-show=&quot;isShow&quot; key=&quot;2&quot;&gt;\u5c1a\u7845\u8c37\uff01&lt;\/h1&gt;\n        &lt;\/transition-group&gt;\n    &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\n    export default {\n        name:&#039;Test&#039;,\n        data() {\n            return {\n                isShow:true\n            }\n        },\n    }\n&lt;\/script&gt;\n\n&lt;style scoped&gt;\n    h1{\n        background-color: orange;\n    }\n    \/* \u8fdb\u5165\u7684\u8d77\u70b9\u3001\u79bb\u5f00\u7684\u7ec8\u70b9 *\/\n    .hello-enter,.hello-leave-to{\n        transform: translateX(-100%);\n    }\n    .hello-enter-active,.hello-leave-active{\n        transition: 0.5s linear;\n    }\n    \/* \u8fdb\u5165\u7684\u7ec8\u70b9\u3001\u79bb\u5f00\u7684\u8d77\u70b9 *\/\n    .hello-enter-to,.hello-leave{\n        transform: translateX(0);\n    }\n\n&lt;\/style&gt;<\/code><\/pre>\n<h3>3\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u7684\u8fc7\u5ea6\u4e0e\u52a8\u753b<\/h3>\n<p>1\u3001\u5b98\u7f51\uff1a<a href=\"https:\/\/animate.style\/\">Animate.css | A cross-browser library of CSS animations.<\/a><\/p>\n<h4>1\u3001\u5b89\u88c5<\/h4>\n<pre><code>npm install animate.css --save<\/code><\/pre>\n<h4>2\u3001\u5bfc\u5165<\/h4>\n<pre><code>import &#039;animate.css&#039;<\/code><\/pre>\n<h4>3\u3001\u4f7f\u7528<\/h4>\n<pre><code class=\"language-vue\">&lt;head&gt;\n  &lt;link\n    rel=&quot;stylesheet&quot;\n    href=&quot;https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/animate.css\/4.1.1\/animate.min.css&quot;\n  \/&gt;\n&lt;\/head&gt;<\/code><\/pre>\n<h4>4\u3001\u4f8b\u5b50<\/h4>\n<pre><code class=\"language-vue\">&lt;template&gt;\n    &lt;div&gt;\n        &lt;button @click=&quot;isShow = !isShow&quot;&gt;\u663e\u793a\/\u9690\u85cf&lt;\/button&gt;\n        &lt;transition-group \n            appear\n            name=&quot;animate__animated animate__bounce&quot; \n            enter-active-class=&quot;animate__swing&quot;\n            leave-active-class=&quot;animate__backOutUp&quot;\n        &gt;\n            &lt;h1 v-show=&quot;!isShow&quot; key=&quot;1&quot;&gt;\u4f60\u597d\u554a\uff01&lt;\/h1&gt;\n            &lt;h1 v-show=&quot;isShow&quot; key=&quot;2&quot;&gt;\u5c1a\u7845\u8c37\uff01&lt;\/h1&gt;\n        &lt;\/transition-group&gt;\n    &lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\n    import &#039;animate.css&#039;\n    export default {\n        name:&#039;Test&#039;,\n        data() {\n            return {\n                isShow:true\n            }\n        },\n    }\n&lt;\/script&gt;\n\n&lt;style scoped&gt;\n    h1{\n        background-color: orange;\n    }\n\n&lt;\/style&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b2c\u4e09\u7ae0\u3001\u4f7f\u7528\u811a\u624b\u67b6 1\u3001\u521d\u59cb\u5316\u811a\u624b\u67b6 1\u3001\u5177\u4f53\u6b65\u9aa4 1\u3001\u7b2c\u4e00\u6b65 1\u3001\u53ea\u6267\u884c\u4e00\u6b21\uff0c\u5c31\u662f\u8bbe\u7f6e\u5168\u5c40\u5b89\u88c5 @vue\/c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[],"class_list":["post-5963","post","type-post","status-publish","format-standard","hentry","category-vue"],"_links":{"self":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/5963","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/comments?post=5963"}],"version-history":[{"count":2,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/5963\/revisions"}],"predecessor-version":[{"id":5965,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/posts\/5963\/revisions\/5965"}],"wp:attachment":[{"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/media?parent=5963"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/categories?post=5963"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/zyg.luchers.cn\/index.php\/wp-json\/wp\/v2\/tags?post=5963"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}