问题
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