I'm newbie to Vue.js. I've been stock in making a dynamic dropdown with Ajax in Vue.js. I have no idea how to populate the select tag with data from the API that is hosted in Google App Engine (GAE) and made in Flask.
File index.html
<div id="app2">
<select v-model="table_list">
<option v-for="item in table_list" :value="item">{{ item }}</option>
</select>
</div>
new Vue({
el: '#app2',
data: {
table_list: []
},
created: function () {
var tableList = this.tableList
axios.get('API_URL').then(function (response) {
for (var i = 0; i < response.data.length; i++) {
tableList.push(response.data[i])
}
}).catch(function (error) {
console.log('failure')
})
}
The data of the API:
["test","test1","test2","test3"]
File flask.py
from flask import Flask, request
from google.cloud import bigquery
from flask import jsonify
app = Flask(__name__)
@app.route('/')
def tables_list():
client = bigquery.Client()
dataset_id = 'test_table'
tables = client.list_tables(dataset_id) # Make an API request.
tables_list = [];
for table in tables:
tables_list.append(table.table_id)
return jsonify(tables_list)
if __name__ == "__main__":
app.run()