javascript - v-for 完成渲染后的 Vue 运行函数
问题描述
我正在v-for
基于params
Vue.js 中的变量动态地在 a 中创建输入字段。输入也是 Twitter typeahead 输入,但它们需要在呈现后进行初始化。typeaheadLoop()
我可以在看到它们被渲染后手动调用,但是我怎样才能自动调用呢?
我需要在完成typeaheadLoop()
后运行该功能v-for params
,我该如何实现?
HTML:
<div v-for="item in params" :key="item">
<label class="col-form-label text-inverse-success">@{{ fromCamelToSentenceCase(item) }}</label>
<div class="typeahead">
<input v-bind:id="item + 'ParamInput'" type="text" class="form-control" :placeholder="'Enter ' + fromCamelToSentenceCase(item)"/>
</div>
</div>
JavaScript:
function typeaheadLoop() {
for(var i = 0; i < vueApp.params.length; i++) {
var param = vueApp.params[i];
if(!param.includes('date')) {
createTypeahead(param, vueApp.dataSource);
}
}
}
function createTypeahead(paramName, dataset) {
var hound = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
cache: false,
url: '/param/' + dataset + '?paramName=' + paramName + '&keyword=%QUERY',
wildcard: '%QUERY'
}
});
$("#" + paramName + "ParamInput").typeahead({
highlight: true,
minLength: 0,
},{
name: 'suggestions',
source: hound,
limit: 10,
display: function(data) {
return data;
},
}
).bind('typeahead:select', function(ev, suggestion) {
console.log(suggestion);
});
}
解决方案
我认为 $nextTick 可能会有所帮助:
mounted: function () {
this.$nextTick(function () {
// Code that will run only after the
// entire view has been rendered
})
}
推荐阅读
- javascript - VueJS - 如何告诉 vue DOM 中的外部变化
- python - 如何在 try 块中正确使用标识?
- javascript - 不是数字没有用firebase更新
- python - Python从子目录动态导入函数
- python - 如何在 PyInputPlus.inputStr() 函数中获取与 blockRegexes 匹配的输入值
- java - 在旧项目中从 RoboGuice 依赖注入库迁移到 Dagger2
- arrays - 使用 vuex 在对象数组上实现撤消/重做
- c# - 如何解决 UWP 中 DependencyPropertiy 加载错误的问题?
- vba - VBA 循环定义范围每 n 行
- python - 如果另一个属性出现在使用 python 的给定列表中,如何提取 XML 属性?