简体   繁体   English

如何从另一个方法获取变量的值? (vue.js 2)

[英]How to get value of variable from method another ? (vue.js 2)

My code is like this : 我的代码是这样的:

<script>
    export default{
        props:... ,
        data(){
            return{
                ...
            }
        },
        computed:{
            ...
        },
        methods:{
            filterBySort: function (sort){
                ...
            },
            filterByLocation: function (location){
                ...
            }
        }
    }
</script>

For example, parameter sort = lowest (on the filterBySort method) 例如,参数sort =最低(在filterBySort方法上)

I want display value of parameter sort on the filterByLocation 我想在filterByLocation上显示参数排序的值

How can I do it? 我该怎么做?

如果你定义变量sort中的数据,并更改它filterBySort方法是这样的: this.sort = lowest ,相同的值将在可用的方法filterByLocation为好。

One of the ways is to set it up in the data properties. 一种方法是在数据属性中进行设置。

<script>
export default{
    props:... ,
    data() {
        return{
          sort: null,
          location: null
        }
    },
    computed:{
        ...
    },
    methods:{
        filterBySort: function (){
            console.log(this.sort)
        },
        filterByLocation: function (){
            console.log(this.location)
        }
    }
}

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

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