你需要从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}/`;
}
});