【问题标题】:laravel livewire wire:click is not working when i do insertAdjacentHTMLlaravel livewire 电线:当我插入 AdjacentHTML 时,点击不起作用
【发布时间】:2021-01-28 19:38:24
【问题描述】:

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)
        })
}

现在wire:click 不工作了。但是我单独对其进行了测试,它运行良好,但在我使用 insertAdjacentHTML 时无法正常工作

点击事件监听的代码是:

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

谢谢!

【问题讨论】:

  • 有什么原因吗?
  • 使用 javascript 添加 wire:click 不起作用。不会有任何 javascript 事件链接到此按钮。 wire:click 应该添加到刀片中。这就是 Livewire 的工作方式,一切都在 Laravel 后端,而不是 JavaScript 前端。

标签: javascript laravel laravel-livewire


【解决方案1】:

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

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

})

【讨论】:

    猜你喜欢
    • 2021-08-29
    • 2021-07-04
    • 2021-01-13
    • 2021-03-10
    • 2022-10-17
    • 1970-01-01
    • 2020-11-24
    • 1970-01-01
    • 2021-02-20
    相关资源
    最近更新 更多