Nativescript-Vue Creating Dinamyc Elements

旧城冷巷雨未停 提交于 2020-01-16 17:09:48

问题


I was wondering how could i create new elements dynamically like buttons, labels, or textfield which are inside a layout. I have the following code:

<AbsoluteLayout ref="abs">
                    <Label :text="L('UserClockIn.info.5')" top="10" left="10" />
                    <Label class="stk-table-row-data" :text="clockInTimes[0]" top="10" left="100" />
                    <Label class="stk-table-row-data" :text="clockInTimes[1]" top="10" left="165" />
                    <Label class="stk-table-row-data" :text="clockInTimes[2]" top="10" left="230" />
</AbsoluteLayout>

I am using nativescript-vue with typescript, i want to create a element like another label or button and add it to the absolute layout.


回答1:


Answered here.

import { Label } from "tns-core-modules/ui/label";

export default {
    methods: {
        addLabel() {
            var label = new Label();
            label.text = "my text";
            // label.top = 10;
            // label.left = 150;
            this.$refs.abs.nativeView.addChild(label);
        }
    }
}

Anyways, it looks like you're creating a grid. Have you considered using a GridLayout?



来源:https://stackoverflow.com/questions/59270461/nativescript-vue-creating-dinamyc-elements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!