用vue写的页面后缀名怎么表示

发布时间:2022-12-28 10:15:02 作者:iii
来源:亿速云 阅读:179

本篇内容主要讲解“用vue写的页面后缀名怎么表示”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“用vue写的页面后缀名怎么表示”吧!

用vue写的页面后缀名是“.vue”。“.vue”文件是一个自定义的文件类型,用类HTML语法描述一个Vue组件;一个vue文件就是一个组件。vue页面有3个组成部分:1、模板(template),即template标签包裹的界面展示代码(HTML代码);2、script标签包裹的业务实现代码(js脚本代码);3、style标签包裹的界面样式代码(css样式代码)。

用vue写的页面后缀名是“.vue”。

.vue 文件是一个自定义的文件类型,用类 HTML 语法描述一个 Vue 组件。每个 .vue 文件包含三种类型的顶级语言块 <template>、<script> 和 <style>,还允许添加可选的自定义块:

<template>
  <div class="example">{{ msg }}</div>
</template>

<script>
export default {
  data () {
    return {
      msg: 'Hello world!'
    }
  }
}
</script>

<style>
.example {
  color: red;
}
</style>

<custom1>
  This could be e.g. documentation for the component.
</custom1>

组件结构讲解

<template>
  <!-- 组件html区域 
  在组件里面的html都必须有一个独立的标签包住所有标签
  -->
  <div>
    <button>按钮</button>
    <button>{{msg}}</button>
  </div>
</template>

<script>
export default {
  // 不再需要el去确定使用范围
  // 组件 里面的data将是一个函数 return一个对象
  //data:function(){return {}}
  data() {
    return {
      msg: "hello"
    };
  },
  methods: {
    alertEvent(value) {
      alert(value);
    }
  },
  created() {
      //这里面语法检测比较严格,直接写console会报错
    window.console.log(this);
    // this.alertEvent(123);
  }
};
</script>

<style>
/* 如果需要引入 外部css 
在css中的导入:
 @import url(./babel.css);
 在js中的导入
 import "./babel.css"
*/
/* @import url(./babel.css); */
@import "./babel.css";
button {
  width: 100px;
}
</style>

如何在组件中引入其它组件

如何在一个组件中引入其它组件,实现一个组装。

组件的使用三步

组件中如何使用外部插件

以axios为例

使用外部插件分为三步

组件间的传值

如果A组件中引入了B组件 ,这样我们称A组件为父组件,B为子组件

父组件传值给子组件

子组件传值给父组件

    this.$parent    //这就代表父组件的vue实例
    //如要修改父组件里面data里的某个值:         this.$parent.父组件里data属性名
    //如果需要调用父组件里面methods里某个方法:   this.$parent.父组件里面methods里方法名
//两个组件,这个是father.vue
<template>
  <div>
    <button @click="btnClick">点我获取数据</button>
    <div>你选中的当前歌曲:{{localSong}}</div>
    <son ref="son" id="son"></son>
  </div>
</template>
<script>
// 组件使用,导包,注册,使用
//1:导包
import axios from "axios";
import son from "./son.vue";
export default {
  data() {
    return {
      songs: [],
      localSong: ""
    };
  },
    //2:注册
  components: {
    son
  },
  methods: {
    btnClick() {
      window.console.log("ref访问:", this.$refs.son.$el);
      window.console.log("原生访问:", document.getElementById("son"));
      //要调接口,是不是要使用axios
      //装包,导包,用包
      axios({
        url:
          "https://autumnfish.cn/search?keywords=神话&_t=" + Math.random() * 100
      }).then(res => {
        //   父组件传递子组件值,在子组件上定义一个ref,通过this.$refs.名字,我们就能访问子组件的实例,也就是可访问子组件data属性与methods方法
        this.$refs.son.songs = res.data.result.songs;
        this.$refs.son.alertEvent();
        window.console.log(res.data.result.songs);
      });
    }
  }
};
</script>
<style>
</style>
//son.vue
<template>
  <ul>
    <li v-for="(item, index) in songs" :key="index" @click="liCLick(item.name)">{{item.name}}</li>
  </ul>
</template>
<script>
// 子组件访问父组件里的data与methods更简单,只需要this.$parent就够了
export default {
  data() {
    return {
      songs: []
    };
  },
  methods: {
    liCLick(name) {
      this.$parent.localSong = name;
      window.console.log("访问父组件:", name, this.$parent);
    },
    alertEvent() {
      alert(123);
    }
  }
};
</script>
<style>
</style>

Vue-cli项目创建

直通车

什么是脚手架

创建项目:

用vue写的页面后缀名怎么表示

用vue写的页面后缀名怎么表示

用vue写的页面后缀名怎么表示

Vue-cli项目结构

项目结构说明:

用vue写的页面后缀名怎么表示

Vue-cli 入口文件main.js分析

到此,相信大家对“用vue写的页面后缀名怎么表示”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

推荐阅读:
  1. Vue 全家桶 + Express 实现的博客(后端API全部自己手写)
  2. vue中怎么利用$set和$delete实现数据监控

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vue

上一篇:vue实现双向绑定的方法有哪些

下一篇:vue中v-if和v-for的区别有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》