1

当用户使用 element plus 敲击按钮时,我需要在按钮上设置延迟(加载)

<el-button type="primary" :loading="delay_search_button" icon="el-icon-search" size="small" style="width: 14.5vh" @click="searchButton"></el-button>
methods: {
    searchButton ()  {
        this.delay_search_button = true;
        setTimeout(() => {
          this.delay_search_button = false;
          console.log(this.delay_search_button)
        }, 2000);
      },
      
  },

但是这段代码不起作用,我做错了什么?

4

1 回答 1

0

您的代码完美运行。我看不出有什么问题。

var Main = {
    data() {
      return {
            delay_search_button: false
      }
    },
    methods: {
        searchButton ()  {
            this.delay_search_button = true;
            setTimeout(() => {
              this.delay_search_button = false;
              console.log(this.delay_search_button)
            }, 2000);
        }          
    }
};
const app = Vue.createApp(Main);
app.use(ElementPlus);
app.mount("#app")
<html>
<head>
<link rel="stylesheet" href="//unpkg.com/element-plus/theme-chalk/index.css">
</head>
<body>
<script src="//unpkg.com/vue@next"></script>
<script src="//unpkg.com/element-plus/dist/index.full.js"></script>
<div id="app">
<div> 
</div>
<el-button type="primary" :loading="delay_search_button" icon="el-icon-search" size="small" @click="searchButton"></el-button>
</div>
</body>
</html>

于 2021-09-09T12:48:17.353 回答