我在我的laravel项目中有一个js文件,其中有一些指向某些资产文件的链接。我试着动态定位这个。我该怎么做??
var textarea = document.getElementById('editor');
sceditor.create(textarea, {
emoticons:{
dropdown: {
':)': '../editor/emoticons/smile.png',
':angel:': '../editor/emoticons/angel.png',
':alien:': '../editor/emoticons/alien.png',
':blink:': '../editor/emoticons/blink.png',
':angry': '../editor/emoticons/angry.png',
':D': '../editor/emoticons/grin.png',
':P': '../editor/emoticons/tongue.png',
':blush:': '../editor/emoticons/blush.png',
':(': '../editor/emoticons/cwy.png',
'<3': '../editor/emoticons/heart.png'
}
},
format: 'xhtml',
icons: 'monocons',
style: '../editor/minified/themes/content/default.min.css'
});我的公用文件夹中有一个包含所有这些内容的文件夹,但是如何动态定位它们。我知道如果这是一个普通的刀片文件,我可以使用{{ asset('') }},如何在这个js文件中做到这一点?
发布于 2022-05-08 03:14:49
我希望在Laravel刀片中,您可以在javascript代码中直接使用刀片语法,如下所示:
var textarea = document.getElementById('editor');
sceditor.create(textarea, {
emoticons:{
dropdown: {
':)': '{{asset('editor/emoticons/smile.png') }} ',
}
},
format: 'xhtml',
icons: 'monocons',
style: '{{ asset(' editor/minified/themes/content/default.min.css') }} '
});我希望它对你有用
发布于 2022-05-09 07:35:25
在head的window.assetUrl = '{{asset('')}}';中(在刀片文件中),您可以使用window.assetUrl = '{{asset('')}}';。然后,在JS文件中,可以调用':)': window.assetUrl + 'editor/emoticons/smile.png'。这样,您的资产URL是动态的(基于应用程序URL是什么)。
https://stackoverflow.com/questions/72156663
复制相似问题