example
example

已解决√ 求助 https://${GetCurrentResourceName()}/是否需要Lua代码的依赖

ZHANIBIN

用户
高级用户
认证用户
黄金
69.08 黄金
RT,我正在尝试将原生Chat中的jspost方法改成可识别资源名称的网络地址,但是不起作用,https://${GetCurrentResourceName()}/这个代码需要再lua写什么依赖吗?
 
你需要从Lua中获取资源名称并传递给前端JavaScript 以下是常用方法:
lua代码:

AddEventHandler('onClientResourceStart', function(resourceName)
if GetCurrentResourceName() == resourceName then
SendNUIMessage({
resourceName = GetCurrentResourceName()
})
end
end)

然后在JavaScript中接收:

window.addEventListener('message', (event) => {
if (event.data.resourceName) {
const resourceName = event.data.resourceName;
// 现在你可以使用resourceName构建URL
const apiUrl = `https://${resourceName}/`;
}
});
 
后退
顶部