組件index.vue中引入接口文件index.js,接口文件index.js中需要獲取組件index.vue日期選擇器中的日期 dateSel 來當作接口的日期參數
index.vue:
1 <el-date-picker 2 v-model="dateSel" 3 size="mini" 4 type="date" 5 :editable="false" 6 :clearable="false" 7 :picker-options="pickerOptions" 8 placeholder="選擇日期" 9 format="yyyy-MM-dd" 10 value-format="yyyy-MM-dd" 12 </el-date-picker>
<script>
import { findResourceUse } from './api/index'
const dateApi = require('./api/index').default export default({ data () { return { dateSel: global.today, pickerOptions: { disabledDate(time) { return time.getTime() > Date.now(); } }, }, created() { dateApi.sendThis(this) }, })
</script>
index.js:
1 const findResourceUseInfo = `${wzUrl}/rmdistributecenter/findResourceUse` // 不重要的接口 2 3 let dateS = null 4 const sendThis = (_this)=> { 5 dateS = _this 6 } 7 export default { 8 sendThis // 暴露函數 9 } 10 11 export function findResourceUse (params) { 12 return req({ 13 url: `${findResourceUseInfo}?orderDate=${dateS.dateSel}`, 14 method: 'get', 15 params: params 16 }) 17 }
調用組件中的方法也是一樣的操作
參考鏈接:https://www.jb51.net/article/195714.htm