The other component we need is a vertical banner hanging up on one of the castle's towers. Its length will change depending on the amount of food or health. This time, we will create a dynamic SVG template so that we can modify the height of the banner.
First, create the component with two props (the color and the ratio) and the height computed property:
For now, we defined our templates in two different ways--we either used the HTML of our page or we set a string into the template option of our components. We will use another method of writing component templates--a special script tag in the HTML. It works by writing the template inside this script tag with a unique ID and referencing this ID when defining the component.
Open the banner-template.svg file, which contains the SVG markup of the banner image we will use as a dynamic template. Copy the content of the file.
In the index.html file, after the <p id="app"> element, add a script tag with the text/x-template type and the banner ID, and paste the svg content inside:
As you can see, this is a standard template with all the syntax and directives available to use. Here, we use the v-bind directive shorthand twice. Note that you can use SVG markup inside all of your Vue templates.
Now, back in our component definition, add the template option with the ID of our script tag template preceded by a hashtag: