client-row
이라는 구성 요소 목록이 있는데 하나를 선택할 때 스타일을 변경하고 싶습니다. 새 행을 선택할 때 이전에 선택한 행에서 스타일을 제거하려고 할 때 문제가 발생합니다.Vue : 스타일 목록 행을 선택했을 때
Vue.component('client-row', {
template: '#client-row',
props: {
client: Object,
},
data: function() {
return {
selected: false
}
},
methods: {
select: function() {
// Does not work properly
el = document.querySelector('.chosen_row')
console.log(el)
if (el) {
el.className = el.className - "chosen_row"
}
this.selected = true
this.$emit('selected', this.client)
}
}
})
<script type="text/x-template" id="client-row">
<tr v-bind:class="{ 'chosen_row': selected }">
<td>{{ client.name }}</td>
<td>{{ client.location_name || 'no location found' }}</td>
<td>{{ client.email || 'no email found' }}</td>
<td><button class="btn btn-sm btn-awaken" @click="select()">Select</button></td>
</tr>
</script>
내가 제대로 selected
재산, 을 설정할 수 있지만 안정적으로 제거 할 수없는 것.
잘 답변을 주셔서 감사합니다. 일단 내가 DOM 조작을 작성하기 시작했다면 나는 그것을 잘못 알고있는 것이므로 처음에 이것을 물었습니다! 'client == selectedClient'는 훨씬 더 좋습니다 :) –
한가지. 내 소품이 선택을 업데이트하지 않는 것 같습니다. 그게 왜 일어날까요? –
잘 모르시겠습니까? 코드를 공유 할 수 있습니까? – kmc059000