Vue实现二级联动

282 阅读1分钟

Vue.config.productionTip = false

new Vue({

el: "#app",

created(){

this.getXq();

},

data(){

return {

xqArr:[],

xqVal:"",

zhouArr:[],

}

},

methods: {

getXq: function () {

new Promise(function (resolve, reject) {

$.ajax({

url: "./xq.json",

success: function (res) {

resolve(res)

},

error: function (err) {

reject(err)

}

})

})

.then(res => {

this.xqArr = res.xqArr;

})

},

changeXq(){

console.log(this.xqVal);

if(this.xqVal=="地球"){

new Promise(function (resolve,reject){

$.ajax({

url: "./dqzhou.json",

success: function (res) {

resolve(res)

},

error: function (err) {

reject(err)

}

})

})

.then(res=>{

this.zhouArr = res.dqzhou;

})

}

if(this.xqVal=="月球"){

new Promise(function (resolve,reject){

$.ajax({

url: "./yqzhou.json",

success: function (res) {

resolve(res)

},

error: function (err) {

reject(err)

}

})

})

.then(res=>{

this.zhouArr = res.yqzhou;

console.log(this.zhouArr)

})

}

\

},

\

},

\

})

\

\