Ant Design Vue 中table表格解析 HTML


Ant Design Vue 中table表格解析 HTML

場景: 后台返回的數據中有HTML,讓前台解析出來

解決方案: 主要使用   scopedSlots  和  slot-scope 和 v-html 

demo:

<template>
    <div>
        <h3>解析HTML的p標簽</h3>
        <a-table :columns="columns" :data-source="data"  :pagination="false" :rowKey="(record,index)=>{return index}">
            <a slot="name" slot-scope="text" v-html="text"> {{ text }}</a>
        </a-table>
    </div>
</template>
<script>

    /* 這是ant-design-vue */
    import Vue from 'vue'
    import Antd, { message,Select } from 'ant-design-vue'  //這是ant-design-vue
    import 'ant-design-vue/dist/antd.css'
    Vue.use(Antd);
    /* 這是ant-design-vue */
    const columns = [
        {
            title: '姓名',
            dataIndex: 'name',
            key: 'name',
            scopedSlots: { customRender: 'name' }, // scopedSlots 這個屬性很關鍵
        },
    ];

    const data = [
        {
            key: '1',
            name: 'daFei_01 <p>我是p標簽</p>',
        },
        {
            key: '2',
            name: 'daFei_02',
        },
    ];

    export default {
        data() {
            return {
                data,
                columns
            }
        },
    };
</script>

<style scoped>

</style>
View Code

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM