在Vue文件中将组件动态添加到父div

时间:2018-07-25 09:51:39

标签: javascript vue.js components

我有一个父组件,该组件根据API响应添加了一些子组件。

父组件已经预先添加了几个组件,我想为其添加新的组件。

def keras_loss(sess,prediction):
  #import package
  from keras.models import Model
  from keras.models import Sequential
  from keras.layers import Dense, Dropout,InputLayer
  from keras.applications.inception_resnet_v2 import InceptionResNetV2
  from keras.applications.inception_resnet_v2 import preprocess_input  
  from keras.preprocessing.image import load_img, img_to_array
  from keras import backend as K

  K.set_session(sess)  #sess is the tensorflow model
  K.set_learning_phase(False)
  base_model = InceptionResNetV2 (input_shape=(None, None, 3), include_top=False, pooling='avg', weights=None)
  x = Dropout(0.75)(base_model.output)
  x = Dense(10, activation='softmax')(x)

  model = Model(base_model.input, x) #load the pretrained model
  model.load_weights('./inception_resnet_weights.h5')
  score = model(prediction)  #prediction is a tf tensor

  return score

在上面的div中,我想基于API响应附加另一个组件。 在这种情况下,$ mount可以提供帮助吗?我不能采用v-for方法,因为多个不同的组件类型来自不同的来源。

1 个答案:

答案 0 :(得分:0)

您应该稍微改变一下方法,在使用Vue时,您不应该考虑直接从DOM中添加/删除任何内容。您应该修改数据,从而导致DOM更改。

我认为您要寻找的是动态components

<!-- Component changes when currentTabComponent changes -->
<component v-bind:is="currentTabComponent"></component>