Skip to content

Instantly share code, notes, and snippets.

@sabbir1991
Created October 30, 2017 16:39
Show Gist options
  • Select an option

  • Save sabbir1991/2ce65edfd71c50c87d06c33f65263bc5 to your computer and use it in GitHub Desktop.

Select an option

Save sabbir1991/2ce65edfd71c50c87d06c33f65263bc5 to your computer and use it in GitHub Desktop.

Revisions

  1. sabbir1991 created this gist Oct 30, 2017.
    55 changes: 55 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,55 @@
    // JS File -- index.js

    Vue.component( 'test-com', {

    template: 'tmpl-test-com',

    data: function() {
    return {
    localizeData: []
    }
    },

    methods: {
    setLocalData: function() {
    var self = this;

    data : {
    action: 'test-set-local-data'
    };

    jQuery.post( NinjaTodo.ajaxurl, data, function(resp) {
    if ( resp.success ) {
    self.localizeData = resp.data;
    }
    });


    }
    },

    created: function() {
    this.setLocalData();
    }
    });

    // ----------------- PHP file

    add_action( 'wp_ajax_test-set-local-data', 'set_localize_data' );

    function set_localize_data() {
    return array(
    'save' => __( 'Save', 'ninja-todo' ),
    'add_new' => __( 'Add New', 'ninja-todo' ),
    'cancel' => __( 'Cancel', 'ninja-todo' )
    );
    }

    // ---------------- .vue file

    <div class="test-class">
    <input type="button" name="save" value="{{ localizeData.save }}" >
    <input type="button" name="add_new_btn" value="{{ localizeData.add_new }}" >
    <input type="button" name="cancel_btn" value="{{ localizeData.cancel }}" >
    </div>