vue-2 模板語法
router/index.js
//1、引入基礎依賴 import Vue from 'vue' import Router from 'vue-router' //2、引入要路由的頁面 import Smarty from "../components/smarty" //3、將Router插件注冊為Vue全局組件 Vue.use(Router) const router = new Router({ routes:[ { path: '/smarty', name: 'smarty', component: Smarty } ] }) export default router
APP.vue
import Vue from 'vue' import App from './App.vue' import router from './router' Vue.config.productionTip = false new Vue({ render: h => h(App), router //添加路由 }).$mount('#app')
<template> <div id="app"> <div> <router-link to="smarty">模板語法</router-link> </div> <div>-------------------------------------</div> <router-view></router-view> </div> </template> <script> export default { name: 'App', } </script> <style> #app { font-family: Avenir, Helvetica, Arial, sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-align: center; color: #2c3e50; margin-top: 60px; } </style>
smarty.vue
<template> <div> <h1>模板語法</h1> <h2>插值語法{{title}}</h2> <div>html:{{html}}</div> "v-html:"<span v-html="html"></span><br /> <input type="button" v-bind:value="buttonTitle" /> 縮寫:<input type="button" :value="buttonTitle" /> <div>計算:{{ num +1 }}</div> <a :href="url">百度</a><br/> <input type="button" value="確認" @click="onsubmit" /> </div> </template> <script> export default { name: 'smarty', data() { return { title: "Vue模板語法標題", html: "hello,<span style='color: red'>張三</span>。", buttonTitle: "確認", num: 10, url: "https://www.baidu.com" } }, methods: { onsubmit(){ alert("確認") } } } </script>
創作不易,轉摘請標明出處。如果有意一起探討測試相關技能可加博主QQ 771268289 博主微信:ding17121598
本文來自博客園,作者:怪圣卡杰,轉載請注明原文鏈接:http://www.rzrgm.cn/dwdw/p/16769590.html
浙公網安備 33010602011771號