【问题标题】:nativescript-checkbox won't shownativescript-checkbox 不会显示
【发布时间】:2019-07-05 16:00:11
【问题描述】:

我正在尝试将 nativescript-checkbox 集成到我的 vue 应用程序中。 vue 示例的用法虽然不是很清楚。他们没有说是否将类导入组件。

但我确实尝试了所有方法,我在我的组件中导入了nativescript-checkbox,但它仍然不会显示。我什至尝试使用CheckBox,而不是文档中的check-box

main.js

Vue.registerElement('CheckBox', () => require('nativescript-checkbox').CheckBox, {
    model: {
        prop: 'checked',
        event: 'checkedChange'
    }
});

Tasks.vue

<template>
    <Page class="page">
        <ActionBar class="action-bar">
            <!--
            Use the NavigationButton as a side-drawer button in Android
            because ActionItems are shown on the right side of the ActionBar
            -->
            <NavigationButton ios:visibility="collapsed" icon="res://menu" @tap="onDrawerButtonTap"></NavigationButton>
            <!--
            Use the ActionItem for IOS with position set to left. Using the
            NavigationButton as a side-drawer button in iOS is not possible,
            because its function is to always navigate back in the application.
            -->
            <ActionItem icon="res://navigation/menu"
                        android:visibility="collapsed"
                        @tap="onDrawerButtonTap"
                        ios.position="left">
            </ActionItem>
            <Label class="action-bar-title" text="Tasks"></Label>
        </ActionBar>

        <GridLayout class="page-content">
            <!--<Label class="page-icon fa" text.decode="&#xf0ae;"></Label>
            <Label class="page-placeholder" :text="message"></Label>-->
            <ListView for="task in tasks">
                <v-template>
                    <!-- Shows the list item label in the default color and style. -->
                    <check-box :text="task.text" style="width: 25%" />
                    <Label :text="task.text" class="item" style="width: 75%" />
                </v-template>
            </ListView>
        </GridLayout>
    </Page>
</template>

<script>
    import * as utils from "~/shared/utils";
    import SelectedPageService from "../shared/selected-page-service";
    import CheckBox from 'nativescript-checkbox';

    export default {
        components: { CheckBox },
        mounted() {
            SelectedPageService.getInstance().updateSelectedPage("Tasks");
        },
        data() {
            return {
                tasks: [
                    {'text': 'One1'},
                    {'text': 'Two'},
                    {'text': 'Three'}
                ],
                isChecked: false
            }
        },
        computed: {
            message() {
                return "<!-- Tasks Page -->";
            }
        },
        methods: {
            onDrawerButtonTap() {
                utils.showDrawer();
            }
        }
    };
</script>

<style scoped lang="scss">
    // Start custom common variables
    @import '../app-variables';
    // End custom common variables

    // Custom styles
    .item {
        padding: 20;
    }
</style>

【问题讨论】:

    标签: javascript vue.js nativescript nativescript-vue


    【解决方案1】:

    当您想将 2 个或更多组件包装在一起时,您必须始终使用布局。所以试试吧,

            <ListView for="task in tasks">
                <v-template>
                    <GridLayout columns="auto,*">
                       <!-- Shows the list item label in the default color and style. -->
                       <check-box :text="task.text" col="0" />
                       <Label :text="task.text" class="item" col="1" />
                     </GridLayout>
                </v-template>
            </ListView>
    

    【讨论】:

    • 谢谢。我是使用 javascript 创建移动应用程序的新手。有一个复选框和一个标签的约定是什么?我应该删除标签并只使用CheckBox 中的text 属性还是保留标签?
    • 这取决于,例如在 Android 上点击标签也会选中/取消选中复选框。可能出于这个目的,您可能想要使用复选框的文本(在 iOS 上,复选框不是标准组件,因此这可能不适用)。或者,如果您更喜欢样式、格式化字符串等,使用单独的标签会很有意义。
    • 当我点击标签时没有任何反应。我必须点击复选框文本来检查它。
    • 它适用于我的 Android,我什至现在仔细检查了 (v8.1)。点击复选框文本,切换复选框状态。
    • 是的,但是如果您在复选框旁边有一个Label,则单击它时不会发生任何事情。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多