laravel livewire导线:当我插入AdjacentHTML时,单击不起作用

时间:2020-10-14 11:49:01

标签: javascript laravel laravel-livewire

Laravel版本:8.7.1

livewire版本:2.x.x

您必须查看代码以了解我的问题

此函数将返回要渲染的模板

function createElementForAttatchment(tit,capt,id){
    let template =
        ` <div class="approval-list-tab display-flex
            flex-direction-column flex-align-item-start
             flex-justify-content-space-between" wire:click="$emit('laucnhLeave',${id})">
                <h1 style="text-align: left">${tit}</h1>
                <h2>${capt}</h2>
            </div>`
    return template
}

下面的代码将从服务器获取数据并执行上述功能

function getDataFromServer(){
        axios.get(appUrl+"/api/attendences/for/approval").then(response=>{
            console.log(response.data)
            let data = response.data.data
            nextPageUrl = response.data.next_page_url
            data.forEach(d => {
                let title = d.first_name + " " + d.last_name
                let caption = "ROll NUMBER : "+d.roll_number + " Class : "+d.student_class_id
                scollingElement.insertAdjacentHTML("beforeend",createElementForAttatchment(title,caption,d.id))
            })
        }).catch(error =>{
            console.log(error)
        })
}

现在连线:点击不起作用。但是我单独测试了它,它工作正常,但是当我使用insertAdjacentHTML

时却无法正常工作

点击事件监听器的代码为:

Livewire.on('laucnhLeave', (id) => {
    alert(id)
})

谢谢!

1 个答案:

答案 0 :(得分:0)

它没有用。所以我写了这样的脚本:

document.getElementbyId('element-id').addEventListener('eventname',()=>{

})