BigCommerce: Vue SDK - Extend component functionalities
Overview
Although extending only the template is usually enough for most customizations, some features may require extending the functionalities of the component. For this sample, again the updated component will be ResultItem.
Â
Prerequisite
Node dependencies:
vue-loader: "^15.9.6"
vue-template-compiler: "^2.6.12"
Â
Steps for customizations
Create a subfolder alongside the Vue SDK initialization file (e.g. assets/js/hawksearch/vue/components)
Create a ResultItem Vue single file component in it.
assets/js/hawksearch/vue/components/ResultItem.vue<template> <div class="custom-classes" v-on:click="onClick"> <p>{{ customMethod() }}</p> </div> </template> <script> import { ResultItem } from '@hawksearch/vue'; export default { extends: ResultItem, methods: { customMethod: function () { return 'Lorem ipsum'; } } }; </script>
Â
Note that in this file both template and scripts are initialized
The default ResultItem component is imported from the Vue SDK and the custom one extends it
A customMethod is additionally defined for this component
The newly created file must be included in the initialization script and attached to his parent
assets/js/hawksearch/vue/index.js... import { ResultListing } from '@hawksearch/vue'; import ResultItem from './components/ResultItem.vue'; ResultListing.components.ResultItem = ResultItem; ...
Â
For additional information on component customizations, follow this article, or review the publically available Vue SDK at https://github.com/hawksearch/vue-hawksearch