
在vue里使用$attrs & inheritAttr实现button禁用效果,直接上DemO代码。
<template> <div> <button :disabled="$attrs.disabled">点击</button> </div> </template> <script> Export default { inheritAttrs: false, } </scrIPt> <style scoped> </style>
<template> <div id="APP"> <parent></Parent> <Button disabled></Button> </div> </template>
<script> import Parent from './components/Parent' import Button from './components/Button'; export default { name: 'app', components: { Parent, Button } } </script>
<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>








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