我正在使用vuejs 2 + axios.我需要发送一个get请求,将一些params传递给服务器,并获得一个PDF作为响应.服务器使用Laravel.
所以
axios.get(`order-results/${id}/export-pdf`, { params: { ... }})
Run Code Online (Sandbox Code Playgroud)
成功请求,但它不会启动强制下载,即使服务器返回正确的标头.
我认为这是一种典型情况,例如,您需要形成PDF报告并将一些过滤器传递给服务器.那怎么可能实现呢?
更新
所以实际上我找到了解决方案.然而同样的方法不适用于axios,不知道为什么,这就是我使用原始XHR对象的原因.所以解决方案是创建一个blob对象和用户createUrlObject函数.示例示例:
let xhr = new XMLHttpRequest()
xhr.open('POST', Vue.config.baseUrl + `order-results/${id}/export-pdf`, true)
xhr.setRequestHeader("Authorization", 'Bearer ' + this.token())
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
xhr.responseType = 'arraybuffer'
xhr.onload = function(e) {
if (this.status === 200) {
let blob = new Blob([this.response], { type:"application/pdf" })
let link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.download = 'Results.pdf'
link.click()
}
}
Run Code Online (Sandbox Code Playgroud)
重要提示:您应该将数组缓冲区作为响应类型
但是,在axios中编写的相同代码返回的PDF为空:
axios.post(`order-results/${id}/export-pdf`, {
data,
responseType: 'arraybuffer'
}).then((response) => {
console.log(response)
let blob …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多答案,但无法弄清楚为什么xdebug不起作用.
php.ini中:
[xdebug]
zend_extension="/usr/lib/php5/20090626/xdebug.so"
Run Code Online (Sandbox Code Playgroud)
php -v:
PHP 5.5.6-1+debphp.org~precise+2 (cli) (built: Nov 21 2013 14:31:41)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies
Run Code Online (Sandbox Code Playgroud)
/usr/lib/php5/20090626/xdebug.so确实存在.php.ini中没有zend优化器.
如果我尝试安装xdebug:
pecl/xdebug is already installed and is the same as the released version 2.2.3
install failed
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我在我的组件中使用vuex和mapGetters帮助.我有这个功能:
getProductGroup(productIndex) {
return this.$store.getters['products/findProductGroup'](productIndex)
}
Run Code Online (Sandbox Code Playgroud)
有可能以某种方式移动它mapGetters吗?问题是我也将一个参数传递给函数,所以我找不到将它放入的方法mapGetters
我使用https://github.com/angular-ui/ui-router库.当我尝试访问索引路由('/')时,我被重定向到404.代码:
angular.module('cr').config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'views/index.html'
});
$urlRouterProvider.otherwise('/404');
});
Run Code Online (Sandbox Code Playgroud)
这段代码出了什么问题?虽然当我使用ui-sref ="home"时它可以工作但是网址看起来像'/#/'但是当用户输入网站名称时他只使用域名,比如'mysite.com',而不是'mysite.com/# /"
我根据文章在本地安装了npm(我不记得URL).所以我的npm包就在~/.npm-packages/.所以gulp在~/.npm-packages/bin/gulp,这是一个链接:gulp -> ../lib/node_modules/gulp/bin/gulp.js
当我跑步时,which gulp我得到了/home/victor/.npm-packages/bin/gulp
当我进入bin目录并运行gulp时,./gulp.js -v我可以看到它的工作原理.但是,当我全局运行gulp时,我遇到了这样的错误:
module.js:338
throw err;
^
Error: Cannot find module '/usr/lib/node_modules/gulp/node_modules/v8flags/3.28.73.flags.json'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/usr/lib/node_modules/gulp/bin/gulp.js:25:22)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:501:10)
Run Code Online (Sandbox Code Playgroud)
所以gulp试图在/ usr/lib中找到模块,但为什么呢?为什么不在我的主目录中?我有所有这些模块~/.npm-packages/lib/node_modules/gulp/node_modules
我完全糊涂了,无法工作.我试图以相同的效果重新安装它.
在转移到vue-cli 3时,我遇到了以下问题.我将插件的CSS导入我的app.scss.
这一行:background-image: url(default-skin.svg);break yarn build,抛出此错误:
Module build failed (from ./node_modules/mini-css-extract-plugin/dist/loader.js):
ReferenceError: navigator is not defined
Run Code Online (Sandbox Code Playgroud)
这是我的vue.config.js:
const path = require('path')
const webpack = require('webpack')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin')
const ASSETS_DIR = 'static'
module.exports = {
assetsDir: ASSETS_DIR,
runtimeCompiler: true,
chainWebpack: config => {
config
.plugin('provide-plugin')
.use(webpack.ProvidePlugin, [{
axios: "axios",
$: "jquery",
jQuery: "jquery",
_: "lodash",
mapGetters: ['vuex', 'mapGetters'],
mapActions: ['vuex', 'mapActions']
}])
.end()
.plugin('copy-plugin')
.use(CopyWebpackPlugin, [
[{
from: path.resolve(__dirname, 'static'),
to: ASSETS_DIR, …Run Code Online (Sandbox Code Playgroud) 某些服务向我的站点发出 HTTP 请求并传递一些输入。这个输入的结构对我来说有点错误,所以我正在尝试修改它。
我制作了一个中间件并将这个中间件附加到我的路线上。句柄方法如下所示:
public function handle($request, Closure $next)
{
$input = $request->all();
// Input modification
$request->replace($input);
\Log::info($request->all()); // Shows modified request
return $next($request);
}
Run Code Online (Sandbox Code Playgroud)
但是在我的控制器中,我得到了旧的输入。另外我有点困惑,因为我也使用 FormRequest,而且我意识到这两个请求是不同的实体。那么如何修改中间件中的输入呢?
我理解正确:如果我想显示403,404等错误的自定义页面,我应该检查app.debug是否设置为false:
if (!Config::get('app.debug')) {
App::error(function(Exception $exception, $code)
{
switch ($code) {
case 403:
return Response::view('errors.403', array(), 403);
case 404:
return Response::view('errors.404', array(), 404);
case 500:
return Response::view('errors.500', array(), 500);
default:
return Response::view('errors.default', array(), $code);
}
Log::error($exception);
});
}
Run Code Online (Sandbox Code Playgroud)
因为,如果我在不检查app.debug的情况下设置App ::错误处理程序,我将始终获取这些自定义页面而不是详细信息
我对吗?
如何删除Laravel 5中包含的所有样板,例如bootstrap/authentication等?在laracasts课程中Jeffrey Way讲述了php artisan fresh命令,但在稳定版本中没有这样的命令
我有一个客户列表,实际上是一个对象数组.我把它存放在Vuex中.我在我的组件中呈现列表,每行都有一个复选框.更确切地说,我使用keen-ui和复选框渲染部分看起来像:
<tr v-for="customer in customers" :class="{ selected: customer.selected }">
<td>
<ui-checkbox :value.sync="customer.selected"></ui-checkbox>
</td>
<td>{{ customer.name }}</td>
<td>{{ customer.email }}</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
因此,复选框直接更改了客户数组,这是坏的:我在Vuex中使用严格模式,它会抛出一个错误.
我想跟踪数组何时更改并调用操作以更改vuex状态:
watch: {
'customers': {
handler() {
// ...
},
deep: true
}
Run Code Online (Sandbox Code Playgroud)
但是它仍然直接改变了客户.我怎样才能解决这个问题?