这是执行提交的方式,但数据永远不会通过
传递const actions ={
updateBtn({commit}, data){
commit("test", data);
console.log("data is"+data);//data here has a value
}
}
const mutations={
test(state, {data}){
console.log(data) //this is always undefined.
}
}
突然哪里出错
答案 0 :(得分:1)
尝试不使用函数参数这样使用。
guard let url = URL(string: "http://www.nakdan.com/GetResult.aspx") else { return }
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.addValue("text/xml; charset=utf-8", forHTTPHeaderField: "Content-Type")
var bodyData = "txt=מה קורה&usr=&pass=&ktivmale=false"
request.httpBody = bodyData.data(using: String.Encoding.utf8);
let task = URLSession.shared.dataTask(with: request as URLRequest){
data,response, error in
print(response!)
if error != nil{
print("error")
return
}
}
task.resume()