简体   繁体   English

Vue.js - 如何使用三元运算符在 vue 中返回 html 和字体真棒图标

[英]Vue.js - How to use ternary operator to return html in vue with font awesome icons

I have the following in vue:我在 vue 中有以下内容:

      <div class="pt-2">
        <button
          class="bg-gradient-to-r from-green-100 to-blue-100 rounded p-3 w-full text-xl font-medium focus:outline-none"
          @click="isLoading = true"
          :disabled="isLoading"
        >
          {{isLoading ? '<i class="fas fa-circle-notch fa-spin"></i>' :
          'Register'}}
        </button>
      </div>

How would I get it to return the icon instead of showing:我如何让它返回图标而不是显示: 在此处输入图像描述

You should use conditional rendering using v-if directive:您应该使用v-if指令使用条件渲染:

   <div class="pt-2">
        <button
          class="bg-gradient-to-r from-green-100 to-blue-100 rounded p-3 w-full text-xl font-medium focus:outline-none"
          @click="isLoading = true"
          :disabled="isLoading"
        >
          <i v-if="isLoading" class="fas fa-circle-notch fa-spin"></i>
          <span v-else >Register</span
        </button>
      </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM