ZBLOG

vue给hotel-type-text的class中添加一个使用content方法 after文字问么加

在Vue中,您可以使用计算属性和绑定语法来动态生成类和内容。以下是一个示例:

  1. <template>
  2. <div :class="hotelTypeClass">
  3. {{ hotelTypeText }}
  4. <span v-if="showAfterText" class="after-text">{{ afterText }}</span>
  5. </div>
  6. </template>
  7. <script>
  8. export default {
  9. data() {
  10. return {
  11. hotelTypeText: "Hotel Type",
  12. showAfterText: true
  13. };
  14. },
  15. computed: {
  16. hotelTypeClass() {
  17. // 根据条件判断是否添加 after-text 类
  18. return ['hotel-type-text', { 'after-text': this.showAfterText }];
  19. },
  20. afterText() {
  21. // 根据条件返回 after 文字内容
  22. return this.showAfterText ? 'After text' : '';
  23. }
  24. }
  25. };
  26. </script>
  27. <style>
  28. .hotel-type-text {
  29. /* 主要的文本样式 */
  30. }
  31. .after-text {
  32. /* after 文字的样式 */
  33. }
  34. </style>

在上面的代码中,hotelTypeClass 计算属性根据 showAfterText 数据属性的值来决定是否添加 after-text 类。同时,定义了 afterText 计算属性来根据条件返回 after 文字内容。

请根据您实际的需求和样式定义进行适当调整。


内容由零声教学AI助手提供,问题来源于学员提问

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=18481

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?