Skip to content

Instantly share code, notes, and snippets.

@sabbir1991
Created October 30, 2017 16:39
Show Gist options
  • Save sabbir1991/2ce65edfd71c50c87d06c33f65263bc5 to your computer and use it in GitHub Desktop.
Save sabbir1991/2ce65edfd71c50c87d06c33f65263bc5 to your computer and use it in GitHub Desktop.
// 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment