[英]how to pass array as argument in coffee-script?
我正在学习coffee-script和vue.js和axio,我从https://github.com/axios/axios找到了一个示例,如下所示
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
}));
在我的vue文件中,我写了这个
<script lang="coffee">
import axios from 'axios'
export default
props: ['author']
data: ->
info: null
mounted: ->
vm = this
axios
.get 'https://api.coindesk.com/v1/bpi/currentprice.json'
.then (resp) ->
vm.info = resp
</script>
我的问题是如何翻译javascript代码
{
params: {
ID: 12345
}
}
到咖啡脚本,以传递参数目录而不声明新参数。
和例子一样
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
我不知道如何在咖啡脚本中传递目录。
我尝试过这些,都失败了
.get 'https://api.coindesk.com/v1/bpi/currentprice.json' (param: {id: 1})
.get 'https://api.coindesk.com/v1/bpi/currentprice.json' {param: {id: 1}}
.get 'https://api.coindesk.com/v1/bpi/currentprice.json' param: {id: 1}
.get 'https://api.coindesk.com/v1/bpi/currentprice.json' {id: 1}
.get 'https://api.coindesk.com/v1/bpi/currentprice.json' id: 1
谢谢。
好吧,我发现了原因。 我之间失去了一个“,”。
之后,我发现我的发布请求变成了选项请求。
之后,我的vue文件看起来像
<script lang="coffee">
import axios from 'axios'
import qs from 'qs'
export default
props: ['author']
data: ->
info: null
mounted: ->
vm = this
axios
.post 'http://localhost/get.request.test', qs.stringify {param: {id: 1}, name: 'phey'}
.then (resp) ->
vm.info = resp
</script>
和请求看起来像
POST /get.request.test HTTP/1.1
Origin: http://localhost:8080
Content-Length: 25
Accept-Language: zh-CN,zh;q=0.9
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Accept: application/json, text/plain, */*
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
Host: localhost
Referer: http://localhost:8080/load
Pragma: no-cache
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
param%5Bid%5D=1&name=phey
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.