javascript - 在 vue.js 中将 url 作为参数传递
问题描述
我将参数传递给也是一个 url 的 url,参数是:profile/foldername/imgname.jpg
当我profile/foldername/imgname.jpg
作为参数传递时,我只进入imgname.jpg
我的 laravel 控制器,但我想将整个 url 作为参数传递。
我正在使用以下代码将图像路径传递给 url:
removeImage: function(index,img_path) {
var img_path = encodeURIComponent(img_path);
axios.get(`/api/backend/delete-gallery/${img_path}`, { headers: this.header() }).then((response) => {
在网络选项卡中获取此网址:
http://localhost:8000/api/backend/delete-gallery/post%2FUTS7C210103124422%2F1256160041.png
路线:
Route::get('delete-gallery/{path}', 'API\Controller@deleteGallery');
在控制器中获取它:
dd($request->path);
非常感谢任何帮助。
解决方案
你有很多方法来处理这个问题,我将在下面提到其中的两个:
- 编码 URI
HTTP://img.com/img.com --> http%3A%2F%2Fimg.com%2Fimg.jpg
并将其发送到后端服务,然后您需要使用urldecode()函数对 PHP 中的字符串进行解码。
let img_path = encodeURIComponent("HTTP://img.com/img.jpg")
- Base64
您还可以使用btoa()对 URL 进行编码,然后将其发送到后端。您唯一需要做的就是 在 PHP 端使用base64_decode()将 URL 解码为原始 URL。
推荐阅读
- css - CSS 和服务器中的子目录 apache/2.4.43 (win64) openssl/1.1.1g php/7.4.8
- android - 更改 EditText 长按菜单文本颜色
- java - Gradle 看不到来自 GRADLE_USER_HOME 的 gradle.properties
- php - 数组按键排序,其中键是衣服尺寸(S、M、L 等)
- xamarin.forms - 对于平板电脑设备的某些显示密度,Xamarin Forms 视图超出屏幕
- arrays - 从 JSON 响应创建轮播
- javascript - Safari浏览器的保证金最高负值问题
- linux - 查找文件中单词的索引并用 bash 替换前面的字符
- postgresql - Postgresql 不会重新建立延迟复制
- java - @Scheduled 的第一个和第三个星期日的 Cron 表达式