K
K
KoRNeT46RuS2019-10-23 09:34:01
Vue.js
KoRNeT46RuS, 2019-10-23 09:34:01

Why is the property not displayed inside the component, but outside all the norms?

Vue.component('tree-items', {
    template: '#tree-template',
    props: {
        item: {
            type: Object,
            required: true,
        },
    },
    data: function () {
        return {
            isOpen: false,
            page: {},
            navigation: {},
        };
    },
    computed: {
        hasChildren: function () {
            return this.toArray(this.item.children).length;
        },
        hasItems: function() {
            if (!this.isUndefined(this.items)) {
                return this.items.length;
            }
            return 0;
        },
    },
    methods: {
        toggle: function () {
            if (this.hasChildren) {
                this.isOpen = !this.isOpen
            }
        },
        setItem: function (_item) {
            this.item = _item;
        }
    },
    mounted: function () {
        this.setItem(this.item);
    }
});

Template
<ul v-for="item in items" :key="item.id">
            <tree-items
                    :item="item"
            ></tree-items>
        </ul>
<script type="text/x-template" id="tree-template">
    {{ item }}
</script>

If the object is displayed not inside the component, then it is printed out, if inside, then it is empty, although the helper in the browser writes that it is.
5daff44a3e86b930711739.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-10-23
@0xD34F Vue.js

<script type="text/x-template" id="tree-template">
    {{ item }}
</script>

What, just text? No, it won't. There must be some element. Do it - you are trying to display them liinside :ul
<script type="text/x-template" id="tree-template">
  <li>{{ item }}</li>
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question