Use vuejs on wordpress

Edward Ziadeh • 19 February 2019
Blog in group Wordpress
0 comments
0 likes

Adding vuejs to wordpress, what do you need to start working with vuejs on wordpress.

First you need to have vuejs cli installed so you can create a new vuejs project.

The thing that we need to make a vuejs work is to connect the js file with the page of the wordpress.

First:

vue create lp

Second:

npm run build

after we do the build we will have a build.js file that we need to connect.

Third:

add_action( 'wp_enqueue_scripts', 'x' );
function enqueue_checkout_scripts() {
	if ( is_page_template( 'template-checkout.php' ) ) {
        // register the Vue build script.
		wp_register_script( // the app build script generated by Webpack.
			'app',
			'http://localhost:8080/dist/build.js',
			array(),
			false,
			true
		);
           
    		// enqueue the Vue app script with localized data.
		wp_enqueue_script( 'app' );
    }
}

Need to change localhost to the domain name.