简体   繁体   中英

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)

I want display value of parameter sort on the 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)
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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