「短文」如何在 Vue 中复制文本到剪贴板
November 04, 2022
1 min
在 VUE 3 具有方便的方式让你可以在当前组件中定义局部样式。使用 style Scoped,您不需要引用一个全局 CSS 文件。通过简单地将CSS放入 style scoped 标签中,CSS将应用于该组件。示例代码如下。
<template> <img alt="Vue logo" src="./assets/logo.png" /> <HelloWorld msg="Welcome to Your Vue.js App" /> </template> <script> import HelloWorld from "./components/HelloWorld.vue"; export default { name: "App", components: { HelloWorld, }, }; </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>
<template> <div class="hello"> <h1>{{ msg }}</h1> <p class="text">This text is in a component with a {{ html }}</p> </div> </template> <script> export default { name: "HelloWorld", data() { return { html: `<style scoped>`, }; }, props: { msg: String, }, }; </script> <!-- Add "scoped" attribute to limit CSS to this component only --> <style scoped> h3 { margin: 40px 0 0; } ul { list-style-type: none; padding: 0; } li { display: inline-block; margin: 0 10px; } a { color: #42b983; } .text { color: pink; } </style>
注:本文属于原创文章,版权属于「前端达人」公众号及 qianduandaren.com 所有,未经授权,谢绝一切形式的转载