用axios.post传一个数组参数使用:JSON.stringify(this.params)

 <form>
<span class="upimg"><img :src="img"><input type="file" class="file" name="file" @change="getFile($event)"></span>
<button @click="submitForm($event)">submit</button>
</form>
 import XLSX from 'xlsx';
export default{
name: 'cqadd',
data(){
return {
file: '',
img: '../src/assets/images/Upload-picture.png',
jsondata: []
}
},
methods: {
//导入excel获取到内容
getFile(event){
//wb 存储读取完成的数据
//jsondata 存储获取excel json数据
var wb,jsondata,that=this;
var f = event.target.files[];
var reader = new FileReader();
reader.onload = function(e){
var data = e.target.result;
wb = XLSX.read(data, {type: "binary"});
that.jsondata = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[]]);
}
reader.readAsBinaryString(f);
},
submitForm(event){
event.preventDefault(); let params = new URLSearchParams(); params.append('jsondata', JSON.stringify(this.jsondata)); this.axios.post('url', params).then((ret)=>{
if(ret.status === ){
this.$router.push(ret.data.requireUrl);
}
})
}
},
mounted(){ }
}

后端接收

$jsondata = $_POST["jsondata"];

$arr = json_decode($jsondata);//需要json_decode()下再使用

 <?php
require '../config/config.php';
$conn = Connect(); $patterns = array('\'', '"');
$replacements = array('&apos', '&quot'); $jsondata = $_POST["jsondata"];
$arr = json_decode($jsondata); $sql = "INSERT INTO cquestion (question, answer, optionone, optiontwo, optionthree, tips) VALUES (?,?,?,?,?,?)"; $stmt = mysqli_stmt_init($conn); if(mysqli_stmt_prepare($stmt, $sql)){
mysqli_stmt_bind_param($stmt, 'ssssss', $question, $answer, $optionone, $optiontwo, $optionthree, $tips);
// 注 此处's'如只给一个字段插入就只写一个s,插入几个字段的数据就写几个 for($i=;$i<count($arr);$i++){
$question = str_replace($patterns, $replacements, $arr[$i]->question);
$answer = str_replace($patterns, $replacements, $arr[$i]->answer);
$optionone = str_replace($patterns, $replacements, $arr[$i]->optionone);
$optiontwo = str_replace($patterns, $replacements, $arr[$i]->optiontwo);
$optionthree = str_replace($patterns, $replacements, $arr[$i]->optionthree);
if(empty($arr[$i]->tips)){
$tips = "";
}else{
$tips = str_replace($patterns, $replacements, $arr[$i]->tips);
}
mysqli_stmt_execute($stmt);
} $arr=[
"status"=>,
"message"=>"add data success",
"requireUrl"=>"/cqlist"
];
echo json_encode($arr);
}else{
echo "创建数据表错误:" . $conn->error;
} $conn->close();
?>

vue项目多列导入的更多相关文章

  1. vue入坑教程(二)在vue项目中如何导入element以及sass

    在项目中导入element以及sass.stylus等方便开发的工具以及UI框架 (1)如何在vue项目中导入elementUI框架 elementUI是饿了么团队开发出来基于vue的前端UI框架,其 ...

  2. vue项目下的导入和导出

    本篇博文主要记录我们在写项目的时候经常需要用到导入和导出. 导入 首先定义一个模态弹窗,一般情况下会使用一个input(设置opacity:0)覆盖在显示的按钮上面 <!-- 3.导入 --&g ...

  3. vue项目使用阿里巴巴矢量图标库教程

    前言:element-ui自带的图标库还是不够全,还是需要需要引入第三方icon,自己在用的时候一直有些问题,参考了些教程,详细地记录补充下. 对于我们来说,首选的当然是阿里icon库 地址:http ...

  4. 基于vue项目的组件中导入mui框架初始化滑动等效果时需移除严格模式的问题

    基于vue项目的组件中导入mui框架初始化滑动等效果时,控制台报错:Uncaught TypeError: 'caller', 'callee', and 'arguments' properties ...

  5. 实战:vue项目中导入swiper插件

    版本选择 swiper是个常用的插件,现在已经迭代到了第四代:swiper4.常用的版本是swiper3和swiper4,我选择的是swiper3. 安装 安装swiper3的最新版本3.4.2: n ...

  6. idea中导入别人的vue项目并运行

    1. 下载node.js 在搭建vue的开发环境之前,先下载node.js,下载地址:https://nodejs.org/en/ https://blog.csdn.net/antma/articl ...

  7. 在vue项目中,解决如何在element表格中循环出图片列!

    效果图: 1,vue项目环境 2,引入element-ui组件 3,制作表格 此处省去制作循环表格数据那步,想看的可以找回我的博客:element中的表格处理:循环出表格数据 今天想在表格出循环出一列 ...

  8. 在nginx上部署vue项目(history模式)--demo实列;

    在很早之前,我写了一篇 关于 在nginx上部署vue项目(history模式) 但是讲的都是理论,所以今天做个demo来实战下.有必要让大家更好的理解,我发现搜索这类似的问题还是挺多的,因此在写一篇 ...

  9. vue项目中一些文件的作用

    原文 简书原文:https://www.jianshu.com/p/38749e5bec3c 大纲 1.vue项目结构 2.主要的配置文件 2.1.package.json 2.2.dev-serve ...

随机推荐

  1. 【转载】获取更多/proc/fd中有关socket的信息

    Q: Looking in /proc/$mypid/fd/, I see these files lrwx------ cm_user cm_user Oct : -> /dev/pts/ ( ...

  2. 集合--Map&&HasMap和TreeMap

    特点:以键值对key,value方式存储的结构     key:Set集合 key能重复,无序的,如果重复,后面的key会把前面的覆盖掉(key必须是唯一的,不唯一,那么后面的value会把前面的va ...

  3. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十三章:计算着色器(The Compute Shader)

    原文:Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十三章:计算着色器(The Compute Shader) 代码工程 ...

  4. 对The Curse of Dimensionality(维度灾难)的理解

    一个特性:低维(特征少)转向高维的过程中,样本会变的稀疏(可以有两种理解方式:1.样本数目不变,样本彼此之间距离增大.2.样本密度不变,所需的样本数目指数倍增长). 高维度带来的影响: 1.变得可分. ...

  5. axios细节之绑定到原型和axios的defaults的配置属性

    把axios绑定到原型 vue开发者一套很好用的实践,一般来说,实践如果能够让大部分人都接受,会逐渐成为一个默认的标准. // 把axios配置到原型上 Vue.prototype.$axios = ...

  6. 16.libgdx根据配置文件生成布局(未完)

    思路: screen分为普通和复杂两种,普通的功能大部分是页面跳转以及简单的crud数据,复杂的单独弄出来 跳转普通的screen,直接根据配置文件调整设置 <layouts> <l ...

  7. LeetCode109 Convert Sorted List to Binary Search Tree

    Given a singly linked list where elements are sorted in ascending order, convert it to a height bala ...

  8. List<object> 转 List<T>

    List<TAXIWAY_CENTER_LINE> kk = allObjs.Where(c => c.ToString() == "AMXM.TAXIWAY_CENTER ...

  9. 谈一谈Python的上下文管理器

    经常在Python代码中看到with语句,仔细分析下,会发现这个with语句功能好强,可以自动关闭资源.这个在Python中叫上下文管理器Context Manager.那我们要怎么用它,什么时候用它 ...

  10. 「BZOJ2654」tree

    「BZOJ2654」tree 最小生成树+二分答案. 最开始并没有觉得可以二分答案,因为答案并不单调啊. 其实根据题意,白边的数目肯定大于need条,而最小生成树的白边数并不等于need(废话),可以 ...