首页 > 解决方案 > 如何在 nativescript vue 中制作反应数组?

问题描述

我知道当我们直接使用索引设置项目时,vue 不会检测到数组的变化,而是使用 Vue.set,并且在 vue.js 中工作正常。但是我正在使用带有本机脚本的 Vue,当我使用 Vue.set(myArray,index,newValue) 时,会出错。ReferenceError Vue 未定义。这是我的脚本:

<script>
    export default {
        methods: {
            comparar: function(caracter, pos) {
                                           
                //This is NOT reactive
                this.palabra_escrita[pos] = caracter

                //  This must be reactive but throws me error
                app.$set(this.palabra_escrita, pos, caracter)
                                    
                }
            
        }, //End methods        
        data() {
            return {
               
                palabra_escrita: [],                
                
            };
        }
    };
</script>

这是我的 app.js 文件:

import Vue from 'nativescript-vue';

import HelloWorld from './components/HelloWorld';

// Uncommment the following to see NativeScript-Vue output logs
 //Vue.config.silent = false;

new Vue({

    template: `
        <Frame>
            <HelloWorld />
        </Frame>`,

    components: {
        HelloWorld
    }
}).$start();

标签: vue.js

解决方案


推荐阅读