跨域问题解决,在index.php中添加如下代码
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:GET, POST, OPTIONS, DELETE");
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
index.php代码
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- import CSS -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
</head>
<style>
.el-table .warning-row {
background: oldlace;
}
.el-table .success-row {
background: #f0f9eb;
}
</style>
<body>
<div id="app">
<el-button @click="batchDelete(tableChecked)" type="primary" size="big">批量删除</el-button>
<el-button @click="add" type="primary" size="big">添加</el-button>
<el-table :data="tableData" style="width: 100%" :key="Math.random()" @select="handleSelectionChange" :row-class-name="tableRowClassName">
<el-table-column type="selection">
</el-table-column>
<el-table-column prop="id" label="ID" width="180">
</el-table-column>
<el-table-column prop="title" label="标题" width="180">
<template slot-scope="scope">
<span class="col-cont" v-html="scope.row.title"></span>
</template>
</el-table-column>
<el-table-column prop="img" label="封面">
<template slot-scope="scope">
<el-image style="width: 100px; height: 100px" :src="scope.row.img">
</el-image>
</template>
</el-table-column>
<el-table-column prop="show" label="是否展示">
<template slot-scope="scope">
<span @click="isShow(scope.row)" style="color:blue;cursor:pointer">
<span v-if="scope.row.show==0">不展示</span>
<span v-if="scope.row.show==1">展示</span>
</span>
<el-switch
v-model="scope.row.show"
active-color="#13ce66"
inactive-color="#ff4949">
</el-switch>
</template>
</el-table-column>
<el-table-column fixed="right">
<template slot="header" slot-scope="scope">
<el-input v-model="search" @change="searchs()" size="mini" placeholder="输入关键字搜索" />
</template>
<template slot-scope="scope">
<el-button @click="handleClick(scope.row,1,scope.$index)" type="text" size="small">编辑</el-button>
<el-button @click="handleClick(scope.row,2,scope.$index)" type="text" size="small">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page.currentPage4"
:page-sizes="page.pagesizes" :page-size="page.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="page.total">
</el-pagination>
</div>
</body>
<!-- import Vue before Element -->
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<!-- import JavaScript -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
<script>
new Vue({
el: '#app',
data: function() {
return {
isRouterAlive: true,
tableData: '',
page: {
total: 3,
pagesize: 5,
currentPage4: 1,
pagesizes: [5, 10, 15]
},
search: '',
tab