{"id":8470,"date":"2023-11-28T20:29:00","date_gmt":"2023-11-28T12:29:00","guid":{"rendered":"https:\/\/wx.kaifamiao.info\/?p=8470"},"modified":"2023-12-02T22:52:21","modified_gmt":"2023-12-02T14:52:21","slug":"vue-zhong-ru-he-dong-tai-de-zai-yuan-su-shang-qie","status":"publish","type":"post","link":"http:\/\/wx.kaifamiao.info\/index.php\/2023\/11\/28\/vue-zhong-ru-he-dong-tai-de-zai-yuan-su-shang-qie\/","title":{"rendered":"Vue \u4e2d\u5982\u4f55\u52a8\u6001\u5730\u5728\u5143\u7d20\u4e0a\u5207\u6362 CSS \u7c7b\uff1f"},"content":{"rendered":"<p>\u5728 Vue \u4e2d\u52a8\u6001\u5730\u5728\u5143\u7d20\u4e0a\u5207\u6362 CSS \u7c7b\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u5f0f\uff0c\u5176\u4e2d\u4e00\u4e9b\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\uff1a<\/p>\n<h3><a id=\"1%E4%BD%BF%E7%94%A8-v-bind-class%E6%88%96%E8%80%85%E7%AE%80%E5%86%99-class\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>1. \u4f7f\u7528 <code>v-bind:class<\/code> \u6216\u8005\u7b80\u5199 <code>:class<\/code><\/h3>\n<p>\u4f60\u53ef\u4ee5\u6839\u636e\u67d0\u4e9b\u6761\u4ef6\u6765\u52a8\u6001\u5730\u7ed1\u5b9a\u4e00\u4e2a\u5bf9\u8c61\u3001\u6570\u7ec4\u6216\u8005\u76f4\u63a5\u4f20\u9012\u7c7b\u540d\u5b57\u7b26\u4e32\u6765\u5207\u6362\u7c7b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u793a\u4f8b\uff1a<\/p>\n<h4><a id=\"%E5%AF%B9%E8%B1%A1%E8%AF%AD%E6%B3%95\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5bf9\u8c61\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div :class=&quot;{ 'active': isActive, 'error': hasError }&quot;&gt;&lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  data() {\n    return {\n      isActive: true,\n      hasError: false\n    };\n  }\n};\n&lt;\/script&gt;\n<\/code><\/pre>\n<h4><a id=\"%E6%95%B0%E7%BB%84%E8%AF%AD%E6%B3%95\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u6570\u7ec4\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div :class=&quot;[isActive ? 'active' : '', hasError ? 'error' : '']&quot;&gt;&lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  data() {\n    return {\n      isActive: true,\n      hasError: false\n    };\n  }\n};\n&lt;\/script&gt;\n<\/code><\/pre>\n<h4><a id=\"%E7%BB%84%E4%BB%B6%E6%96%B9%E6%B3%95%E6%88%96%E8%AE%A1%E7%AE%97%E5%B1%9E%E6%80%A7\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u7ec4\u4ef6\u65b9\u6cd5\u6216\u8ba1\u7b97\u5c5e\u6027<\/h4>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div :class=&quot;classObject&quot;&gt;&lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  data() {\n    return {\n      isActive: true,\n      hasError: false\n    };\n  },\n  computed: {\n    classObject() {\n      return {\n        active: this.isActive,\n        error: this.hasError\n      };\n    }\n  }\n};\n&lt;\/script&gt;\n<\/code><\/pre>\n<h3><a id=\"2%E4%BD%BF%E7%94%A8%E5%AF%B9%E8%B1%A1%E6%88%96%E6%95%B0%E7%BB%84%E7%BB%91%E5%AE%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>2. \u4f7f\u7528\u5bf9\u8c61\u6216\u6570\u7ec4\u7ed1\u5b9a<\/h3>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u5728\u4e00\u4e2a\u5bf9\u8c61\u6216\u6570\u7ec4\u4e2d\u52a8\u6001\u5730\u5b9a\u4e49\u7c7b\u540d\uff0c\u7136\u540e\u5c06\u5176\u7ed1\u5b9a\u5230\u5143\u7d20\u4e0a\u3002<\/p>\n<h4><a id=\"%E5%AF%B9%E8%B1%A1%E8%AF%AD%E6%B3%95\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u5bf9\u8c61\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div :class=&quot;classObject&quot;&gt;&lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  data() {\n    return {\n      classObject: {\n        active: true,\n        'text-danger': true\n      }\n    };\n  }\n};\n&lt;\/script&gt;\n<\/code><\/pre>\n<h4><a id=\"%E6%95%B0%E7%BB%84%E8%AF%AD%E6%B3%95\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u6570\u7ec4\u8bed\u6cd5<\/h4>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div :class=&quot;classArray&quot;&gt;&lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  data() {\n    return {\n      classArray: ['active', 'text-danger']\n    };\n  }\n};\n&lt;\/script&gt;\n<\/code><\/pre>\n<h3><a id=\"3%E5%8A%A8%E6%80%81%E7%B1%BB%E5%90%8D%E7%9A%84%E7%BB%91%E5%AE%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>3. \u52a8\u6001\u7c7b\u540d\u7684\u7ed1\u5b9a<\/h3>\n<p>\u4f60\u4e5f\u53ef\u4ee5\u901a\u8fc7\u65b9\u6cd5\u6765\u52a8\u6001\u5730\u8fd4\u56de\u7c7b\u540d\u3002<\/p>\n<pre><code class=\"language-vue\">&lt;template&gt;\n  &lt;div :class=&quot;getClass&quot;&gt;&lt;\/div&gt;\n&lt;\/template&gt;\n\n&lt;script&gt;\nexport default {\n  data() {\n    return {\n      isActive: true\n    };\n  },\n  methods: {\n    getClass() {\n      return this.isActive ? 'active' : '';\n    }\n  }\n};\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u5141\u8bb8\u4f60\u6839\u636e\u7ec4\u4ef6\u7684\u72b6\u6001\u3001\u8ba1\u7b97\u5c5e\u6027\u6216\u8005\u65b9\u6cd5\u6765\u52a8\u6001\u5730\u4e3a\u5143\u7d20\u6dfb\u52a0\u6216\u79fb\u9664 CSS \u7c7b\u3002\u9009\u62e9\u9002\u5408\u4f60\u9700\u6c42\u7684\u65b9\u5f0f\uff0c\u5e76\u6839\u636e\u60c5\u51b5\u4f7f\u7528\u5408\u9002\u7684\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Vue \u4e2d\u52a8\u6001\u5730\u5728\u5143\u7d20\u4e0a\u5207\u6362 CSS \u7c7b\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u65b9\u5f0f\uff0c\u5176\u4e2d\u4e00\u4e9b\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\uff1a 1. \u4f7f\u7528 v-bin [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[114],"tags":[],"class_list":["post-8470","post","type-post","status-publish","format-standard","hentry","category-vue"],"_links":{"self":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8470","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/comments?post=8470"}],"version-history":[{"count":2,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8470\/revisions"}],"predecessor-version":[{"id":14117,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/posts\/8470\/revisions\/14117"}],"wp:attachment":[{"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/media?parent=8470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/categories?post=8470"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wx.kaifamiao.info\/index.php\/wp-json\/wp\/v2\/tags?post=8470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}