×

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

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

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

  1. <template>
  2.  <div>
  3.   <button :disabled="$attrs.disabled">点击</button>
  4.  </div>
  5. </template>
  6.   
  7. <script>
  8.  export default {
  9.    inheritAttrs: false,
  10.  }
  11. </script>
  12.   
  13. <style scoped> 
  14. </style>

App.vue

  1. <template>
  2.  <div id="app">
  3.  <Parent></Parent>
  4.  <Button disabled></Button>
  5.  </div>
  6. </template>

JS

  1. <script>
  2. import Parent from './components/Parent'
  3. import Button from './components/Button';
  4.   
  5. export default {
  6.  name: 'App',
  7.  components: {
  8.  Parent,
  9.  Button
  10.  }
  11. }
  12. </script>

css

  1. <style>
  2. #app {
  3.  font-family: Avenir, Helvetica, Arial, sans-serif;
  4.  -webkit-font-smoothing: antialiased;
  5.  -moz-osx-font-smoothing: grayscale;
  6.  text-align: center;
  7.  color: #2c3e50;
  8.  margin-top: 60px;
  9. }
  10. </style>

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

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

发表评论: