我有这个组件,并且我想以状态驱动方式不可行的方式对其子元素进行一些操作。所以我想在querySelector
其中使用一个语句和一个。但是我怎样才能将它的范围限定为元素呢?页面中有组件的多个实例,因此无法使用类或 id。我怎样才能做到这一点?
这是一个简化的代码:
<script>
export let value = ''
export let readonly = true
$: if (value && !readonly){
// selects the first element in the document, not the one from this instance
const nd = document.querySelector('.forminput')
// Do something with nd
}
</script>
<textarea bind:value wrap="soft" rows="1" class="forminput"></textarea>