×

在Vue里使用$attrs & inheritAttr实现button禁用效果

作者:andy0012021.01.22来源:Web前端之家浏览:4575评论:0
关键词:js

在Vue里使用$attrs & inheritAttr实现button禁用效果,直接上DEMO代码。

<template>
 <div>
  <button :disabled="$attrs.disabled">点击</button>
 </div>
</template>
  
<script>
 export default {
   inheritAttrs: false,
 }
</script>
  
<style scoped> 
</style>

App.vue

<template>
 <div id="app">
 <Parent></Parent>
 <Button disabled></Button>
 </div>
</template>

JS

<script>
import Parent from './components/Parent'
import Button from './components/Button';
  
export default {
 name: 'App',
 components: {
 Parent,
 Button
 }
}
</script>

css

<style>
#app {
 font-family: Avenir, Helvetica, Arial, sans-serif;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
 text-align: center;
 color: #2c3e50;
 margin-top: 60px;
}
</style>

您的支持是我们创作的动力!
温馨提示:本文作者系 ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/vuejs20210122a1.html

网友评论文明上网理性发言 已有0人参与

发表评论: