vue-router从入门到放弃

用命令号创建一个 mytest 文件夹

vue init webpack mytest

初始化 init myproject之后 手动安装vue-router

7426605-96edc6a1f858dc4f.png
image.png

再创建三个.vue文件,注意引用文件图片的时候加上./

引入node_modules文件夹模块 不需要加 ./
引入文件要加

<template>
  <div>
    <img class="myImg" src="./timg.jpeg" alt="" />
    <p>这是一只猫</p>
  </div>
</template>

<script>
  export default {
    name: "cat"
  }
</script>

<style scoped>
  .myImg{
    width: 300px;
  }
</style>

<template>
  <div id="app">
    <!--router-view 相当于将main中component的内容加载到这个地方-->
    <router-view ></router-view>
    <router-link to="/dog">小狗</router-link>
    <router-link to="/cat">小猫</router-link>
    <router-link to="/alpaca">羊驼</router-link>

    <!--<router-link :to="/dog">小狗</router-link>-->
    <!--<router-link :to="/cat">小猫</router-link>-->
    <!--<router-link :to="/alpaca">羊驼</router-link>-->
  </div>
</template>
7426605-89383eb086f08e59.png
image.png
7426605-ef48e9664429d89d.png
image.png
7426605-9eb1f321447dbbb5.png
image.png
7426605-fa963c38cbfa5040.png
image.png

猜你喜欢

转载自blog.csdn.net/weixin_33882452/article/details/87234847
今日推荐