简体   繁体   English

当一个刀片包含在另一个刀片中时,Vue.js 被忽略

[英]Vue.js ignored when a blade is included in another blade

I have created a product card view in Laravel.我在 Laravel 中创建了一个产品卡视图。 the card has a simple "accordion" ('Show Details') - closed by default - that is managed by Vue.js as well as a Vue.js quantity counter that changes the weight value in grams if you add products.该卡有一个简单的“手风琴”(“显示详细信息”) - 默认关闭 - 由 Vue.js 以及 Vue.js 数量计数器管理,如果您添加产品,该计数器会更改重量值(以克为单位)。 It all functions very well on the card's view and it looks like this (closed):从卡片上看,这一切都很好,看起来像这样(关闭): 卡关闭

I have another view in which I query my DB for product names with Vue.js to display all products of the same name as a result.我有另一个视图,其中我使用 Vue.js 查询我的数据库以获取所有同名的产品作为结果。 The problem is when the cards are displayed on that "parent" view, they all appear with the accordion open and the counter is not responsive.问题是当卡片显示在“父”视图上时,它们都显示为手风琴打开并且计数器没有响应。 It looks like so:它看起来像这样:

开卡

As you can see, the tailwindcss code is rendered without a problem but the Vue.js is being completely ignored (Although the parent view's Vue.js functions work perfectly) What am I doing wrong?如您所见,tailwindcss 代码渲染没有问题,但 Vue.js 被完全忽略(尽管父视图的 Vue.js 功能完美运行)我做错了什么? What am I missing here?我在这里想念什么? Why are the directives inside the included blade being ignored?为什么包含刀片内的指令被忽略?

Here is the Vue.js method that manages the (product cards) views integration onto the parent (product name search) view:这是管理(产品卡)视图集成到父(产品名称搜索)视图的 Vue.js 方法:

        setGearItem(gearItem) {

            this.gearItem = gearItem;
            this.modal = false;
            console.log(gearItem);

            document.getElementById("displaySearch").innerHTML = "";

            axios.get('/send-name-get-ids/' + this.gearItem)
                .then((response) => {
                    console.log(response.data);
                    if (response.data.length === 0) {
                        document.getElementById("displaySearch").innerHTML = `"<strong>${gearItem}</strong>" was not found in our database. You can add it manually:`;
                        this.generalForm = true;
                        return;

                    } else {
                        for (let i = 0; i < response.data.length; i++) {
                            axios.get('/gearitem/' + response.data[i])
                                .then((response) => {
                                    console.log(response.data);
                                    document.getElementById("displaySearch").innerHTML += response.data;
                                    this.generalForm = false;
                                })
                                .catch((error) => {
                                    document.getElementById("displaySearch").innerHTML =
                                        "No items to display";
                                    console.log(error);
                                });
                        }
                    }
                });
        },

The problem is in the .innerHTML method as Vue.js ignores anything added via this method even if it's an AJAX.问题出在.innerHTML方法中,因为 Vue.js 会忽略通过此方法添加的任何内容,即使它是 AJAX。 The solution consists on changing the controller to return a JSON and not a blade view, then using the JSON to populate a Vue.js component to create the item's card. The solution consists on changing the controller to return a JSON and not a blade view, then using the JSON to populate a Vue.js component to create the item's card. the setGearItem() method was changed like so: setGearItem()方法更改如下:

        setGearItem(gearItem) {

            this.gearItem = gearItem;
            this.modal = false;
            console.log(gearItem);
            document.getElementById("displaySearch").innerHTML = "";
            this.displayItemCard = false;

            axios.get('/send-name-get-ids/' + this.gearItem)
                .then((response) => {
                    console.log(response.data);
                    this.gearItemId = response.data[0];
                    if (response.data.length === 0) {
                        document.getElementById("displaySearch").innerHTML = 
                        `<p class="text-gray-700 ">
                        <strong class="capitalize">${gearItem}</strong>
                         was not found on our database. <br>You're free to add it manually! </p>`;

                        this.generalForm = true;
                        return;

                    } else {

                        this.displayItemCard = true;
                        
                    }
                });
        },

the displayItemCard just activates the card component on the view and displays the correct card according to the id. displayItemCard只是在视图上激活卡片组件并根据 id 显示正确的卡片。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM