# #The operating environment of this tutorial: Windows 7 system, vue3 version, DELL G3 computer.The vue component consists of 3 parts: 1. template, which sets the template structure of the component; 2. script, which sets the JavaScript behavior of the component; 3. style, which sets the style of the component. Each component must contain a template template structure, and script behavior and style are optional components; "" is a container tag provided by Vue, which only functions as a wrapper and will not be rendered as Real DOM elements. " is a container tag provided by Vue. It only plays a wrapping role. It will not be rendered as a real DOM element.
vue is a framework that fully supports component development. The suffix name of the component specified in vue is .vue. I have come into contact with it before The App.vue file is essentially a vue component. Each .vue component is composed of 3 parts, namely:
<template> <!-- 当前组件的DOM结构,需要定义到template 标签的内部 </ template>
Use the directive in the template
In the component The node supports the use of the instruction syntax learned previously to assist developers in rendering the DOM structure of the current component. The code example is as follows:
<template> <h1>这是App根组件</h1> <!--使用{{ }}插值表达式--> <p>生成一个随机数字: {{ (Math. random() * 10). toFixed(2) }}</p> <!-- 使用v-bind 属性绑定--> <p :title="new Date(). tol ocaleTimeString()">我在黑马程序员学习vue. js</p> <!--属性v-on事件绑定 <button @click=”showInfo">按钮</button> </template>
In the vue 2.x version, the DOM structure within the node only supports a single root node:
<template> <!-- vue 2.x 中,template 节点内的所有元素,最外层"必须有“唯一的根节点进行包裹,否则报错--> <div> <h1>这是App根组件</h1> <h2>这是副标题</h2> </div> </ template>
<template> <!--这是包含多个根节点的template 结构,因为h1标签和h2标签外层没有包裹性质的根元素--> <h1>这是App根组件</h1> <h2>这是副标题</h2> </template>
##vue stipulates: The