Views: 177
Last Modified: 28.04.2022

  Global variable $Bitrix details

All integration methods are located inside a single variable $Bitrix that is available at any level of BitrixVue 3 component: in calculated property, function, life cycle hook or a template.

Access to the $Bitrix variable

The $Bitrix variable is built based in the calculated property. Thanks to this, it can be called in a customary notation in any component location:

  • In template

    in text interpolation format (not available for all methods):

    template: `
    	{{ $Bitrix.Loc.getMessage('EXAMPLE_PHRASE') }}
    `
    

    Template elements:

    template: `
    	<div @click="$Bitrix.eventEmitter.emit('module:component:eventName')" :title="$Bitrix.Loc.getMessage('EXAMPLE_PHRASE')">Click me</div>
    `
    

  • In component

    The access is performed in the component in the same manner as in any other variable – via this.. However, there are specifics.

    All component webhooks and methods are accessed via the variable this.$Bitrix:

    created()
    {
    	this.$Bitrix.eventEmitter.subscribe('module:component:eventName', () => alert('catch!'));
    }
    

    computed:
    {
    	counter()
    	{
    		return this.$Bitrix.Log.getMessage('DEMO_COUNTER', {'#COUNTER#': this.counter}); 
        }
    }
    

    There is an exception: webhook beforeCreate. You need to query via this.$bitrix:

    beforeCreate()
    {
    	this.$bitrix.Loc.setMessage({'DEMO_COUNTER': 'Counter: #COUNTER#'});
    }
    

    This exception has its roots from the integration method. Because the $Bitrix variable was created based on the calculated property, it's not yet available in the webhook beforeCreate. That's why its necessary to query the original property this.$bitrix.

  Method list






Courses developed by Bitrix24