Vue: How to prompt this .$message

Because the writing is very ordinary, so write together, this passed this

//Pop-up message
function alertMessage(th,action,a){
    var msg,type;
    switch(a){
        case '1':
            type='success';
            msg = action+'success';
            break;
        case '2':
            type='warning';
            msg = action;
            break;
        case '3':
            type='info';
            msg = 'cancel'+action;
            break;
        case '4':
            type='error';
            msg = action+'fail';
            break;
        default:
            break;
    }
    th.$message({
        message: msg,
        type: type,
    });
}

Simplified, the message content is more free, but it will be more written when used

//Pop-up message
            alertMessage(th,action,msg){
                this.$message({
                    message: msg,
                    type: action,
                });
            },

Read More: