vue模板挂在元素内部直接书写
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
<h1>
{{title}}
</h1>
<p>
名称:<input type="text" v-model="newproducts.name">
库存:<input v-model="newproducts.stock" type="number">
<button @click="addProduct">添加</button>
</p>
<ul>
<li v-for="(item,i) in products":key="i">
{{item.name}}
库存:{{item.stock}}
</li>
</ul>
</div>
<p>
hello
</p>
<script src="vue.min.js"></script>
<script>
var vm=new Vue({
//配置模板
data:{
//配置数据
title:"商品管理",
newproducts:{
name:"默认名称",
stock:10
},
products:[
{name:"iphone",stock:10},
{name:"huawei",stock:5},
{name:"xiaomi",stock:2},
],
},
methods:{
addProduct(){
this.products.push({
name:this.newproducts.name,
stock:this.newproducts.stock,
});
}
}
});
vm.$mount("#app")
</script>
</body>
</html>
vue模板template方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<p id="app">
hello
</p>
<script src="vue.min.js"></script>
<script>
var vm=new Vue({
//配置模板
template:`<div id="app">
<h1>
{{title}}
</h1>
<p>
名称:<input type="text" v-model="newproducts.name">
库存:<input v-model="newproducts.stock" type="number">
<button @click="addProduct">添加</button>
</p>
<ul>
<li v-for="(item,i) in products":key="i">
{{item.name}}
库存:{{item.stock}}
</li>
</ul>
</div>`,
data:{
//配置数据
title:"商品管理",
newproducts:{
name:"默认名称",
stock:10
},
products:[
{name:"iphone",stock:10},
{name:"huawei",stock:5},
{name:"xiaomi",stock:2},
],
},
methods:{
addProduct(){
this.products.push({
name:this.newproducts.name,
stock:this.newproducts.stock,
});
}
}
});
vm.$mount("#app")
</script>
</body>
</html>
vue模板render方法
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="app">
</div>
<p>
hello
</p>
<script src="vue.min.js"></script>
<script>
var vm=new Vue({
//配置模板
render(creatElement){
return creatElement("h1",["abc"])
},
data:{
//配置数据
title:"商品管理",
newproducts:{
name:"默认名称",
stock:10
},
products:[
{name:"iphone",stock:10},
{name:"huawei",stock:5},
{name:"xiaomi",stock:2},
],
},
methods:{
addProduct(){
this.products.push({
name:this.newproducts.name,
stock:this.newproducts.stock,
});
}
}
});
vm.$mount("#app")
</script>
</body>
</html>
模板中些什么