Skip to content Skip to sidebar Skip to footer

How To Check If There Is No Selected Value Then Select First Item?

I am trying to add new values inside each object in Array and if there is no selected tag then it will choose first option from drop down. The point is that there is also another f

Solution 1:

If I understand correctly, you are trying to add props to selectedProduct. Please let me know if this logic looks correct to you:

 isTagSelected(selectedProduct) {
    if (!selectedProduct.tagTitle && selectedProduct.tags.length) {
        this.$set(selectedProduct, 'tagId', selectedProduct.tags[0].id)
        this.$set(selectedProduct, 'tagTitle', selectedProduct.tags[0].title)
        return selectedProduct.tagTitle
    }
    else { 
        return selectedProduct.tagTitle}
    }

Post a Comment for "How To Check If There Is No Selected Value Then Select First Item?"