Vue export default external call internal methods

<script>
    // methods  
    $(document).on("refresh", ".pull-to-refresh-content", function (e) {
        this.getList();//  getList  
        console.log("123");
    });
    
    export default {
        name: "friends",
        data() {
            return {
                articles: []
            }
        },
        methods: {
            getList: function () {
                
            }
        },
    }
</script>
Apr.05,2021

you can unload getlist and write

outside export default as a pure function.
function getList (pagesize,pages){
  return this.$axios.get('xxx') .....
}

then in methods

methods: {
getListInExpDau(){
 getList(10,1) ....
}

this method may be possible

<script>
    // methods  
    $(document).on('refresh', '.pull-to-refresh-content', function (e) {
        vm && vm.getList();//  getList  
        console.log('123');
    });
    
    var vm = null;
    
    export default {
        name: "friends",
        data() {
            return {
                articles: []
            }
        },
        created: function() {
            vm = this
        },
        methods: {
            getList: function () {
                
            }
        },
    }
</script>

you can write

like this.
<script>
    // methods  
    $(document).on('refresh', '.pull-to-refresh-content', function (e) {
        friends.methods.getList();//  getList  
        console.log('123');
    });
    
    const friends = {
        name: "friends",
        data() {
            return {
                articles: []
            }
        },
        methods: {
            getList: function () {
                
            }
        },
    }
    export default friends;
</script>

if there are multiple component instances, which instance's method? do you want to call?
have you considered what happens if the event is triggered after the component is destroyed and the method of the destroyed instance is called?

Please write these codes honestly in mounted


this can be written in it

export default {
        name: "friends",
        data() {
            return {
                articles: []
            }
        },
        mounted() {
            $(document).on('refresh', '.pull-to-refresh-content', () => {
                this.getList();
                console.log('123');
            });
        },
        destroyed() {
            $(document).off('refresh', '.pull-to-refresh-content');
        },
        methods: {
            getList: function () {
                
            }
        },
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3acba-2c25b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3acba-2c25b.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?