我正在使用一个没有Vue.js包装器的库。库以动态的方式在DOM中追加元素。
我希望能够用Vue将v-model属性绑定到这些元素,并在我的模型中添加它们。
我过去曾在其他反应性框架(如Knockout.js )中这样做过,但我无法找到一种使用vue.js的方法。
这样做有报酬吗?这应该是我认为的几行之一:
var div = document.createElement('div');
div.setAttribute('v-model', '{{demo}}');
[VUE CALL] //tell vue.js I want to use
我动态地创建组件:
<component is="tab"/>
如何为该组件添加道具?我试着:
<component is="tab" my-props="test" />
我在控制台出错了:
[Vue warn]: Attribute "type" is ignored on component <component> because the component is a fragment instance: http://vuejs.org/guide/components.
我正在使用模板for-循环动态生成$ref名称。
如果我控制台记录了for-循环中的特定项(参见示例),则可以到达它。但是,当我接受相同的引用并调用一个函数(如focus()或scrollToView() )时,控制台就会非常困惑,并抛出一个错误:
vue.js:1743 TypeError: this.$refs.element2.focus is not a function
所以我想说清楚:
console.log(this.$refs['element2']); <-- WORKS!
this.$refs['element2'].focus();