// 默认布局为(不需要写) display: flex; flex-direction: column; // 横向局部改为 flex-direction: row;
<template>
// 支持的数组写法
<text :class="[isError ? 'isError' : 'isRight']"></text>
// 不支持对象写法
<text :class="{isError}"></text>
</template>
<template>
// 可以修改字体大小和颜色
<text class='text'>文本内容</text>
// 不可以修改字体大小和颜色
<view class='text'>文本内容</view>
</template>
<style>
.text {
color: red;
font-size: 28rpx;
}
</style>
// 不支持的CSS margin: auto; display: ...; content: ...; animation: ...; width: vw、%; height: vh、%; background-image: ...; // 不支持的CSS属性 border-radius: 百分比无效;
// 文本溢出
@mixin line($lineNum, $width: 100%) {
/* 一行时 */
@if $lineNum == 1 {
// App端
/* #ifdef APP-PLUS */
lines: 1; // 1或n
text-overflow: ellipsis;
/* #endif */
// 其他端
/* #ifndef APP-PLUS */
overflow:hidden;
text-overflow:ellipsis;
white-space:nowrap;
width: $width;
/* #endif */
} @else {
/* 多行时 */
// App端
/* #ifdef APP-PLUS */
lines: $lineNum; // 1或n
text-overflow: ellipsis;
/* #endif */
// 其他端
/* #ifndef APP-PLUS */
overflow: hidden;
-webkit-line-clamp: $lineNum;
display: -webkit-box;
text-overflow: ellipsis;
word-wrap: break-word;
white-space: normal !important;
-webkit-box-orient: vertical;
/* #endif */
}
}
// 使用 @include line(1, 400rpx); // 单行 @include line(2); // 多行
// App导航栏高度 uni.getSystemInfoSync().safeArea.top + 'px' // 小程序导航栏高度 uni.getMenuButtonBoundingClientRect().top + 'px'
const safeArea = uni.getSystemInfoSync().safeArea const paddingBottom = safeArea.bottom - safeArea.height + 'rpx'
//只支持dark和light
// #ifdef APP-PLUS
plus.navigator.setStatusBarStyle('dark')
// #endif
// 使用动画的CSS属性、动画时间、动画过渡效果、动画延迟时间 transition-property: transform; transition-duration: 0.2s; transition-timing-function: ease; transition-delay:0.1s;
// HBuilderX 3.1.0之前需要分开写 border-top: 1px; border-style: solid; border-top-color: #eee; // HBuilderX 3.1.0+ 开始支持简写样式 border-top: 1px solid #eee;
// 1、创建动画 uni.createAnimation() // 2、页面滚动 uni.pageScrollTo() // 3、节点布局交互(交叉观察器) uni.createIntersectionObserver()
/* #ifndef APP-PLUS */ padding-bottom: calc(env(safe-area-inset-bottom)); /* #endif */
<template>
<rich-text :nodes='htmlNodes'/>
</template>
<script>
// nvue仅支持node节点渲染,所以要将HTML转换成node节点
import parseHtml from './html-parse.js'
export default {
data () {
return {
htmlStr: `
<h1>我的日记</h1>
<p>今天天气真好</p>
<p>适合出去玩</p>
`,
htmlNodes: []
}
},
onLoad () {
this.getContent()
},
methods: {
getContent () {
// 将HTML文本转换成node节点
this.htmlNodes = parseHtml(this.htmlStr)
}
}
}
</script>
// 计算缓存
export const computedCache = () => {
return new Promise(resolve => {
plus.cache.calculate((size) => {
let cachSize = ''
size = parseInt(size)
if (size === 0) {
cachSize = ''
} else if (size < 1024) {
cachSize = size + 'B'
} else if (size < 1048576) {
cachSize = (size / 1024).toFixed(2) + 'KB'
} else if (size < 1073741824) {
cachSize = (size / 1048576).toFixed(2) + 'MB'
} else {
cachSize = (size / 1073741824).toFixed(2) + 'GB'
}
resolve(cachSize)
})
})
}
// 清除缓存
export const clearCache = (cb) => {
uni.showLoading({
title: '清理中…'
})
const os = plus.os.name
if (os === 'Android') {
const main = plus.android.runtimeMainActivity()
const sdRoot = main.getCacheDir()
const files = plus.android.invoke(sdRoot, 'listFiles')
const len = files.length
for (let i = 0; i < len; i++) {
const filePath = '' + files[i] // 没有找到合适的方法获取路径,这样写可以转成文件路径
plus.io.resolveLocalFileSystemURL(filePath, (entry) => {
if (entry.isDirectory) {
entry.removeRecursively(() => { // 递归删除其下的所有文件及子目录
uni.showToast({
title: '缓存清理完成',
duration: 2000
})
cb()
}, (e) => {
console.log(e.message)
})
} else {
entry.remove()
}
}, () => {
console.log('文件路径读取失败')
})
}
} else { // ios
plus.cache.clear(() => {
uni.showToast({
title: '缓存清理完成',
duration: 2000
})
cb()
})
}
}
// 默认边框色
$border: #e4e7ed;
// nvue端
/*
此处加上!important并是因为目前*.nvue页面编译到H5时,
App.vue的样式会被uni-app的view元素的自带border属性覆盖,导致无效,
所以为了多端兼容,必须要加上!important
App端兼容性较好,直接使用0.5px去实现细边框,不使用伪元素形式实现
*/
/* #ifdef APP-NVUE */
.border {
border-width: 0.5px!important;
border-color: $border!important;
border-style: solid;
}
.border-t {
border-top-width: 0.5px!important;
border-color: $border!important;
border-top-style: solid;
}
.border-l {
border-left-width: 0.5px!important;
border-color: $border!important;
border-left-style: solid;
}
.border-r {
border-right-width: 0.5px!important;
border-color: $border!important;
border-right-style: solid;
}
.border-b {
border-bottom-width: 0.5px!important;
border-color: $border!important;
border-bottom-style: solid;
}
.border-tb {
border-top-width: 0.5px!important;
border-bottom-width: 0.5px!important;
border-color: $border!important;
border-top-style: solid;
border-bottom-style: solid;
}
/* #endif */
// 非nvue端
/* #ifndef APP-NVUE */
.border,
.border-b,
.border-l,
.border-r,
.border-t,
.border-tb {
position: relative;
}
.border-b:after,
.border-l:after,
.border-r:after,
.border-tb:after,
.border-t:after,
.border:after {
content: ' ';
position: absolute;
left: 0;
top: 0;
pointer-events: none;
box-sizing: border-box;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
width: 200%;
height: 200%;
transform: scale(0.5, 0.5);
border: 0 solid $border;
z-index: 1;
}
.border-t:after {
border-top-width: 1px;
}
.border-l:after {
border-left-width: 1px;
}
.border-r:after {
border-right-width: 1px;
}
.border-b:after {
border-bottom-width: 1px;
}
.border-tb:after {
border-width: 1px 0;
}
.border:after {
border-width: 1px;
}
/* #endif */
@import './assets/style/border.scss';
// 1.作为类名使用
<template>
<view class='border-tb'></view>
</template>
// 2.作为选择器继承
<template>
<view class='cell'></view>
</template>
<style lang='scss' scoped>
.cell {
@extend .border-tb;
}
</style>

appBindWx () {
const that = this
uni.getProvider({
service: 'oauth',
success: (res) => {
//支持微信、qq和微博等
if (~res.provider.indexOf('weixin')) {
uni.login({
provider: 'weixin',
success: ({authResult}) => {
// 微信返回的数据见下方图片
// 请求接口完成绑定
},
fail: (res) => {
console.log('App微信获取用户信息失败', res)
}
})
}
}
})
}


const shareAppToMp = (shareInfo, cb) => {
// 建议将图片下载到本地再进行分享,防止有些图片存在鉴权导致无法分享成功
uni.downloadFile({
url: 'xxx', // 图片路径
success (res) {
if (res.statusCode === 200) {
uni.share({
provider: 'weixin', // 分享服务提供商
// WXSceneSession分享到聊天界面、WXSceneTimeline分享到朋友圈、WXSceneFavorite分享到微信收藏
scene: 'WXSceneSession', // provider为weixin 时必选
type: 5, // 图文、纯文字、纯图片、音乐、视频、小程序,5为小程序
imageUrl: res.tempFilePath, // 本地图片地址
title: 'title', // 小程序分享标题
miniProgram: {
id: 'gh_xxxxxxxxxx', // 小程序原始ID
path: '/pages/homePage/index', // 小程序分享的页面
type: 0, // 小程序版本类型,0正式版、1测试版、2-体验版,默认为0
webUrl: 'xxxxx' // 兼容低版本的网页链接,可选
},
success () {
uni.showToast({
title: '分享成功!',
duration: 2000
})
cb()
},
fail (e) {
console.log('分享失败原因:', e)
}
})
}
}
})
}
配置正确的情况下,打包成App后才能成功分享,否则会提示以下错误

quitApp () {
switch (uni.getSystemInfoSync().platform) {
// 安卓
case 'android':
plus.runtime.quit()
break
// ios
case 'ios':
plus.ios.import('UIApplication').sharedApplication().performSelector('exit')
break
}
}
<template>
<ul @click='clickParent'>
<!-- 小程序阻止冒泡 -->
<li @click.stop='clickChild'>子元素</li>
</ul>
</template>
<script>
export default {
methods: {
clickParent () {
console.log('点击父元素')
},
clickChild (e) {
console.log('点击子元素')
// App阻止冒泡
// #ifdef APP-NVUE
e.stopPropagation()
// #endif
}
}
}
</script>
我正在编写一个包含C扩展的gem。通常当我写一个gem时,我会遵循TDD的过程,我会写一个失败的规范,然后处理代码直到它通过,等等......在“ext/mygem/mygem.c”中我的C扩展和在gemspec的“扩展”中配置的有效extconf.rb,如何运行我的规范并仍然加载我的C扩展?当我更改C代码时,我需要采取哪些步骤来重新编译代码?这可能是个愚蠢的问题,但是从我的gem的开发源代码树中输入“bundleinstall”不会构建任何native扩展。当我手动运行rubyext/mygem/extconf.rb时,我确实得到了一个Makefile(在整个项目的根目录中),然后当
Sinatra新手;我正在运行一些rspec测试,但在日志中收到了一堆不需要的噪音。如何消除日志中过多的噪音?我仔细检查了环境是否设置为:test,这意味着记录器级别应设置为WARN而不是DEBUG。spec_helper:require"./app"require"sinatra"require"rspec"require"rack/test"require"database_cleaner"require"factory_girl"set:environment,:testFactoryGirl.definition_file_paths=%w{./factories./test/
我已经在Sinatra上创建了应用程序,它代表了一个简单的API。我想在生产和开发上进行部署。我想在部署时选择,是开发还是生产,一些方法的逻辑应该改变,这取决于部署类型。是否有任何想法,如何完成以及解决此问题的一些示例。例子:我有代码get'/api/test'doreturn"Itisdev"end但是在部署到生产环境之后我想在运行/api/test之后看到ItisPROD如何实现? 最佳答案 根据SinatraDocumentation:EnvironmentscanbesetthroughtheRACK_ENVenvironm
我有两个Rails模型,即Invoice和Invoice_details。一个Invoice_details属于Invoice,一个Invoice有多个Invoice_details。我无法使用accepts_nested_attributes_forinInvoice通过Invoice模型保存Invoice_details。我收到以下错误:(0.2ms)BEGIN(0.2ms)ROLLBACKCompleted422UnprocessableEntityin25ms(ActiveRecord:4.0ms)ActiveRecord::RecordInvalid(Validationfa
我们的git存储库中目前有一个Gemfile。但是,有一个gem我只在我的环境中本地使用(我的团队不使用它)。为了使用它,我必须将它添加到我们的Gemfile中,但每次我checkout到我们的master/dev主分支时,由于与跟踪的gemfile冲突,我必须删除它。我想要的是类似Gemfile.local的东西,它将继承从Gemfile导入的gems,但也允许在那里导入新的gems以供使用只有我的机器。此文件将在.gitignore中被忽略。这可能吗? 最佳答案 设置BUNDLE_GEMFILE环境变量:BUNDLE_GEMFI
这似乎非常适得其反,因为太多的gem会在window上破裂。我一直在处理很多mysql和ruby-mysqlgem问题(gem本身发生段错误,一个名为UnixSocket的类显然在Windows机器上不能正常工作,等等)。我只是在浪费时间吗?我应该转向不同的脚本语言吗? 最佳答案 我在Windows上使用Ruby的经验很少,但是当我开始使用Ruby时,我是在Windows上,我的总体印象是它不是Windows原生系统。因此,在主要使用Windows多年之后,开始使用Ruby促使我切换回原来的系统Unix,这次是Linux。Rub
我正在玩HTML5视频并且在ERB中有以下片段:mp4视频从在我的开发环境中运行的服务器很好地流式传输到chrome。然而firefox显示带有海报图像的视频播放器,但带有一个大X。问题似乎是mongrel不确定ogv扩展的mime类型,并且只返回text/plain,如curl所示:$curl-Ihttp://0.0.0.0:3000/pr6.ogvHTTP/1.1200OKConnection:closeDate:Mon,19Apr201012:33:50GMTLast-Modified:Sun,18Apr201012:46:07GMTContent-Type:text/plain
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt
前言一般来说,前端根据后台返回code码展示对应内容只需要在前台判断code值展示对应的内容即可,但要是匹配的code码比较多或者多个页面用到时,为了便于后期维护,后台就会使用字典表让前端匹配,下面我将在微信小程序中通过wxs的方法实现这个操作。为什么要使用wxs?{{method(a,b)}}可以看到,上述代码是一个调用方法传值的操作,在vue中很常见,多用于数据之间的转换,但由于微信小程序诸多限制的原因,你并不能优雅的这样操作,可能有人会说,为什么不用if判断实现呢?但是if判断的局限性在于如果存在数据量过大时,大量重复性操作和if判断会让你的代码显得异常冗余。wxswxs相当于是一个独立