1

I need to do {{item.icon}} pull as a html data not string but ı don't know how to do that, is there are anyway to do that please help me out

I have this code:

    <div class="box my-5" v-for="(item, index) in items" :key="index" >
        <div class="innerBox">
            <router-link to="/ninethPage">
                <div  class="card Fcard d-flex  flex-row justify-content-center align-items-center" style="padding: 1rem 2rem !important">
                    <span v-html="icon"> </span>
                    <p>{{item.title}}</p>
                </div>
            </router-link>
            <router-view></router-view>
        </div>
    </div>
</div>


export default {
        el: '#app',
        data() {
            return {
                items: [
                    {title: 'Android', icon: <i class="fab fa-android mx-3 img-fluid" style="font-size: 1.5rem;" ></i>},
                    {title: 'IOS', icon: <i class="fab fa-apple mx-3 img-fluid" style="font-size: 1.5rem;" ></i>}
                ]
            }
        },
        components:{
            Header
        }
    }
`
5
  • :v-html="item.icon" ? Commented Dec 9, 2021 at 9:39
  • It wont work man <div class="card Fcard d-flex flex-row justify-content-center align-items-center" style="padding: 1rem 2rem !important"> <span :v-html="item.icon"> </span> <p>{{item.title}}</p> </div> return { items: [ {title: 'Android', icon: '<i class="fab fa-android mx-3 img-fluid" style="font-size: 1.5rem;" ></i>'}, {title: 'IOS', icon: '<i class="fab fa-apple mx-3 img-fluid" style="font-size: 1.5rem;" ></i>' } ] } Commented Dec 9, 2021 at 9:53
  • All icons from items should be in string format: icon: "<i>my-icon</i>" Commented Dec 9, 2021 at 10:34
  • I already do that, no errors but icon doesnt show items: [ {title: 'Android', icon: '<i class="fab fa-android mx-3 img-fluid" style="font-size: 1.5rem;" ></i>'}, {title: 'IOS', icon: '<i class="fab fa-apple mx-3 img-fluid" style="font-size: 1.5rem;" ></i>' } ] } Commented Dec 9, 2021 at 12:35
  • Inspect elements in dev tools, check if <i>...</i> exists in span Commented Dec 9, 2021 at 12:39

1 Answer 1

1

icon: <i class=... is JSX syntax that creates an element and needs to be used with render function instead of a template. It should be a string, icon: '<i class=...'.

There is no icon property, it should be <span v-html="item.icon">.

It's impractical to specify the whole icon element. If only <i> classes differ, it can be icon: 'fa-android', and be used with:

<i class="class="fab mx-3 img-fluid" style="font-size: 1.5rem" :class="item.icon"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.