Created
February 7, 2021 15:56
-
-
Save guillaumeduhan/5302237e4cfd65fdce3926766ec1d4f5 to your computer and use it in GitHub Desktop.
Wordpress Plugin Development with Vue.js - Multiples instances
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function createNewInstance(myInstanceId) { | |
| Vue.component('button-counter', { | |
| data: function () { | |
| return { | |
| count: 0 | |
| } | |
| }, | |
| template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>' | |
| }) | |
| new Vue({ el: '#instance-' + myInstanceId }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Plugin Name: Test-Plugin | |
| * Author: Guillaume Duhan | |
| * Version: 1.0.0 | |
| * Description: This plugin aims to display a GDPR bar to allow/disallow cookies usage. | |
| * | |
| */ | |
| add_shortcode('my-plugin', 'pluginFunction'); | |
| wp_enqueue_script('vue', 'https://cdn.jsdelivr.net/npm/vue/dist/vue.js'); | |
| wp_enqueue_script('app', plugin_dir_url(__FILE__) . 'app.js'); | |
| function pluginFunction() { | |
| $randomId = uniqid(); | |
| echo "<div id='instance-{$randomId}'><button-counter></button-counter></div>"; | |
| echo "<script type='text/javascript'>createNewInstance(" . json_encode($randomId) . ");</script>"; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment