我正在调用一个端点来带回一个对象,该对象确实获取数据,但速度不足以让组件获取数据并呈现。相反,组件在应该有数据的地方使用空白值呈现。
如果我在创建时断点代码,那么可能一秒钟后继续,文本会正确呈现。
如何实现它在数据返回之前不呈现?
我的 API 调用:
checkScenarioType: function () {
this.$http.get('ScenariosVue/GetScenarioTypeFromParticipant/' + this.ParticipantId).then(response => {
// get body data
this.ScenarioType = response.body.value;
if (this.ScenarioType.timeConstraint) {
store.commit('switchConstraint');
}
}, response => {
// error callback
});
}
Run Code Online (Sandbox Code Playgroud)
有问题的组件:
var questionArea = Vue.component('questionarea', {
props: ["scenariotype"],
data: function () {
return ({
position: "",
vehicleType: ""
});
},
methods: {
transformValuesForDisplay: function () {
switch (this.scenariotype.perspective) {
case 1: {
this.position = "Driver";
this.vehicleType = "Autonomous";
break;
}
case 2: {
this.position …Run Code Online (Sandbox Code Playgroud) 应用程序需要能够以工作的 Json 和 Xml 格式返回数据。但是,与此 API 交互的应用程序在其结果中不支持命名空间。
<Item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
以前在此版本之前,我必须编写自定义 xml serilaiser 来为我执行此操作:
public static string Serialise<T>(T model) where T : class, new()
{
// Initalise the Xml writer with required settings.
XmlWriterSettings settings = new XmlWriterSettings
{
OmitXmlDeclaration = true
};
// Set the namespaces accordingly.
XmlSerializerNamespaces xmlNamespaceOverride = new XmlSerializerNamespaces();
xmlNamespaceOverride.Add("", "");
string xml = "";
// Create a new string writer.
using (StringWriter stringWriter = new StringWriter())
{
// And a new Xmlwriter.
using (XmlWriter writer …Run Code Online (Sandbox Code Playgroud)