javascript - Vue 回调更新数据但 3rd 方组件无法重新渲染
问题描述
Vue Date Dropdown的值应在conditions
更改时更新。目前,watch
成功更新selectedDate
但无法重新渲染date-dropdown
。
<template>
<div id="app">
<div>{{selectedDate}}</div> <-- this value is updated after getFilter()
<date-dropdown default="1995-01-10" v-model="selectedDate"/> <-- this component holds old/default value: 1995-01-10
<b-button @click="getFilter()" variant="primary">update</b-button>
</div>
</template>
<script>
import axios from 'axios';
import DateDropdown from "vue-date-dropdown";
const SERVER_URL = 'http://localhost:9000';
const instance = axios.create({
baseURL: SERVER_URL,
timeout: 1000
});
export default {
name: 'App',
components: {
DateDropdown
},
props: {
},
data () {
return {
selectedDate: '',
filter: {
name: 'Filter22With2Conditions',
conditions: [
{ type: 'date', clause: 'until', data: '02.02.1990' },
]
}
...
watch: {
filter: function () {
this.selectedDate = this.filter.conditions[0].data;
}
},
methods: {
getFilter: function() {
let self = this;
instance.get('/api/filters?name=Filter22With2Conditions')
.then(function(response) {
console.log('getFilter:response: ' + JSON.stringify(response.data))
self.filter = response.data;
})
.catch(function(error) {
console.log('getFilter: error: ' + error)
self.errors.push(error);
})
},
...
}
解决方案
推荐阅读
- google-app-engine - 如何将 Helidon 应用程序部署到 Google Cloud App Engine?
- python - 使用文件向特定 API 发布请求
- r - 给定 B1 的值,如何使用 Predict() 线性模型
- c++ - 为什么不接受具有默认分配参数的函数作为 0-arg 生成器?
- javascript - 使用 js 将 JSON 转换为 CSV
- scala - 连接函数返回的 n 个列表
- sql - 加权平均数和按组的总分
- javascript - 是否有等效于 path.resolve() 的 os 包?
- r - 如何修改文件中的标题?
- php - 当它们具有相同的值时,如何将结果连接成一个字符串?